Can Sub & Form Button Have Same Name?

Soule

Registered User.
Local time
Yesterday, 18:05
Joined
Jan 6, 2012
Messages
28
Hi, Everyone,

I want to click a form button and run code in a STANDARD module (not the "behind the form" class module).

I noticed the name (not the Caption) of my form button was different than the name of my Public Sub, so I changed the name of my
Sub to match the name of the button. I started getting an error message.

1) Are both Subs and buttons considered objects in Access?

2) Should my Subs and buttons have different names?

Any bit of information to clear this up for me will be appreciated. Thank you!

Frank
 
Subs, controls, modules, classes and the project all need to have different names.

You can have the same names for objects with different scopes. For example names of controls, private subs and functions within a module can be reused in another module.
 
Solved:

Hi, Galaxiom - thanks for your time and effort replying to my post.

I decided to change my names back...they're all different now.

I used Event Procedures in my Event property to point to them.

Thank you.

Frank
 
Just to clarify. A control has a sub associated with it automatically through its name and the event.

controlname_eventname

eg: MyControl_Click

Access spits the dummy when you use the name of a control in any other way within the same scope.

Public subs and functions are methods of the object whose module holds them. Consequently child objects cannot have the same name as any method of their parent.
 

Users who are viewing this thread

Back
Top Bottom