Error about duplicate names

JiTS

Ciao!
Local time
Tomorrow, 00:56
Joined
Dec 12, 2003
Messages
77
Hi,

Problemsituation:
I've got 2 forms (main and sub). In the main form I created a button with the name "exit". I also created a button in the sub form with the same name, because the button uses the same function.

After that an error came up about duplicate names.

Question:
Do I have to use a different name for each button/textbox/etc. in my database? Or is there a way to use a button/textbox/etc. that's already created?


Greetz,
JiTS :)
 
The word "Exit" is a command. I would strongly advise against using that word as a name for anything. Perhap name your field "txtExit" or something like that. You may also want to name your button a different name like "btnExit".
 
Do I have to use a different name for each button/textbox/etc. in my database? Or is there a way to use a button/textbox/etc. that's already created?
Yes, in VBA you must name each control using a unique name.

If you aim is to re-use code, there are ways around this problem. Among the easiest is to write your code as a function. Then in each event/button where you want the code to run enter a reference like this:
=YourFunctionName("your_optional_parameters")

If you don't want to write the code as a function, write it as a "normal" sub, then reference it from your other event code. Say you want to run the same code from the After Update event of the txtExit text control that you've already got in the Click event of your cmdExit command button:
Code:
Private Sub txtExit_AfterUpdate()
    cmdExit_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom