3

Ive been working on a data entry form to input lines in a delivery plan in excel. After many manual tests and a few modules to run primitive unit tests, i got it working flawlessly on my local prototype .xlsm workbook. Below is an example of the form and a github repo containing the vba code.

Github repo of NDA safe example data and VBA code

enter image description here

After uploading it to sharepoint and testing it again, no problems appeared for myself. When i then released it to my colleages, one of them ended up with a "duplicate declaration" compilation error. This error somehow cascaded across machines, bricking the code to open the form, untill i replaced the form module with a backup. The form opens and works, with no problem, on all other computers ive tested it on.

The debugger points me to clsLeveringsPlanForm.show in modFormShowerButton.bas as the duplicate declaration. Trying to fix this by defining the form as an instance of clsLeveringsPlanForm, then using that instance results in the "Private frm As clsLeveringsPlanForm" as duplicate declaration. The weird thing is that im able to run the form on multiple other computers at the same time, but not after his run.

Attribute VB_Name = "modFormShowerButton"
' ========= modFormShowerButton.bas =========
Option Explicit


Public Sub Show_New_Line_Form()
    clsLeveringsPlanForm.Show vbModeless
    Call RefreshMasterProductList
End Sub

Sadly im not able to reproduce the error on a local copy, but theres one stored in the github repo. If i am missing some crucial information about forms always breaking because of concurrent editing, version differences or any other hints, i would greatly appreciate the help. :)

2
  • 1
    Try this for me. Open VBE. Click on Debug-Compile VBA Project. Do you get the same error? Commented Aug 14 at 18:20
  • @SiddharthRout When i compile the project, i get no compile errors on my machine. Just for documentations sake, i get no errors on pre "published", sharepoint, and a copy of sharepoint workbooks Commented Aug 15 at 8:08

1 Answer 1

6

I was able to reproduce the “Duplicate definition” error with the file BARNDOMSFEJL 140825.xlsm and successfully fixed it on my computer. Here’s what I did:

  1. Removed the form clsLeveringsPlanForm from the project.

  2. Cleared the code in clsLeveringsPlanForm.frm starting from Option Explicit (leaving the definitions intact).

  3. Re-imported the modified clsLeveringsPlanForm.frm.

  4. Manually re-added the code to the form.

After these steps, the error disappeared. I’m not certain if this will work on your system

Update: I think I got a bit closer to the the culprit. You have got a frame on your form with the name fraGauge and in the code of your form you have got the line

Private WithEvents fraGauge As MSForms.Frame    ' ensure your frame is named fraGauge

So, it seems, after all, the error message is correct. As soon as I remove this line and leave everything else as it is all works fine.

PS What is the line good for anyway? IMHO as you have a frame on your form with the name fraGauge you don’t need to (and must not) redeclare it with Private WithEvents
Interestingly, you can add the line above, run Debug/Compile, and execute the code without any errors. However, as soon as you close and reopen the file, you encounter the error message Duplicate definition.

Sign up to request clarification or add additional context in comments.

3 Comments

Would this require building the code from a freshly added form? I tried exporting the form as backup and stripping the code down to only fields and functions with dim ... Adding each function back, and recompiling, gives no compile errors in my local copy. When i then try to put the rebuilt form into the sharepoint document and compiling, i get the "duplicate definition" error on first compile with my pc. Trying to compile again after no code changes, the error then goes away on my pc. Ill try the rebuilding process in the sharepoint workbook, and report back. Thanks for the help :)
Doing this in sharepoint makes the form work on the problem computer, but now previously working computers hit the compile error. Thankfully if they quit out the IDE and click the button again, sometime 2-3 times, then the form opens. Its now a quest for stability, but atleast its not useless now. Thank you :)
Fascinating that the ide doesnt catch it well enough to point to the line. I originally added the line because i was debating adding every UI element at runtime, like i do with the labels inside fraGauge, but i decided not to. So that field is a fragment i forgot to remove in tandem with developing modGauge. Nice spotting man, and again thank you very much for the help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.