Sub and GoTo Err Names Duplicity

GoToHell

Registered User.
Local time
Today, 09:21
Joined
Apr 22, 2010
Messages
10
Hi,

I would like to know if there could be a problem if two subs in two different forms have the same name (in a simultaneous multiple users access database interface).

And also if I can name two GoTo Err identicaly in the same form and in different forms?

Thanks in advance,
 
Cool, I had a 50% chance :)

As far as I know, the golden rules are never to use a reserved word for the name of a function, field or anything (date, year, form etc.) and don't have the same name for two procedures or functions - it can only produce problems

Good weekend all!
 
Thank you all,

What could possibly happen if I name two identical procedures the same way in two seperate forms? (tell me there is only one in a billion chance for an error to happen I don't want to go all over my code again for this)

And How could I name differently two procedures called
Private Sub Form_Open(Cancel As Integer)
in two different forms?


Am I not supposed to specify that this thread was solved somwhere?
 
Last edited:
Well, the form_open refers to an event, so you can't change that.

If you name two procedures or functions the same, Access will freak and come back with an error when you try calling either one - so best not to do it really.
 
I'm sorry I thought that a procedure and an event were the same !
 
Ah not quite - the help file is better than me at defining them though :)
 
:D Don't be so tough with yourself

Ok thanks everyone it has been very helpfull, keep going!
 
Private Sub Form_Open(Cancel As Integer)
or even
Public Sub Form_Open(Cancel As Integer)

is fine behind many different Forms.

They are both methods of the Form Class module.


The same goes for…

Private Sub TestIt()
or even
Public Sub TestIt()

They too are both methods of the Form Class module.


If you need to call these procedures from within the limited scope of the Class module you just call them by their name, if they are Private or Public.
If you want to call them as…
Me.TestIt
or
Forms(Me.Name).TestIt
or
Forms("Form1").TestIt
then TestIt() needs to be Public.



If you need to call them from outside of the Class module then you will need to specify the Class module name and the procedures need to be Public.

So, if…
Public Sub TestIt()
exists on Form2 and we want to call it from Form1 we need Form2 to be open and use…
Forms("Form2").TestIt
to call it.

If…
TestIt()
also exists on Form1 at the time
Forms("Form2").TestIt
is called then Forms("Form2").TestIt is called.

The thing that defines the difference between which TestIt() is called is the Class module name, not the procedure name.

I would suggest taking the time to TestIt.
 
i think you are safe

if you have similarly defined functions/subs with global scope, the compiler will let you know, and will report an error

the insidious issue concerns scope of these procedures though. it is easy to end up with similarly named functions at both form and global level. Access will use the most local one first, if it can - which can be confusing if you dont realise you have done this.

Note that Shift-F2 in code, will jump to the function/sub that is being referenced.
 

Users who are viewing this thread

Back
Top Bottom