public sub not found

  • Thread starter Thread starter davidmound via AccessMonster.com
  • Start date Start date
D

davidmound via AccessMonster.com

I have a public sub declared in a form's module as follows:
Public Sub psfrmReservations_NewReserv()

When I call this proc from another form, it says it can't be found. What's up
with that? (and its definitely not a typo)

Thanks,
David

for further reading:
I usually keep my public subs/functions in standard modules, but in this case,
I need to work with a number of other subs that are private to the form, so I
thought it would be easier to put the public sub in that form (rather than
make all the form's subs public).
 
davidmound via AccessMonster.com said:
I have a public sub declared in a form's module as follows:
Public Sub psfrmReservations_NewReserv()

When I call this proc from another form, it says it can't be found.
What's up with that? (and its definitely not a typo)

A public Sub in a class module (such as a form's module) can only be
called from outside that module by way of a reference to an intance of
the class object. So you would prefix the call to the Sub with a
reference to the form, along these lines:

Forms!YourFormName.psfrmReservations_NewReserv
 
I have a public sub declared in a form's module as follows:
Public Sub psfrmReservations_NewReserv()

When I call this proc from another form, it says it can't be found. What's up
with that? (and its definitely not a typo)

Thanks,
David

for further reading:
I usually keep my public subs/functions in standard modules, but in this case,
I need to work with a number of other subs that are private to the form, so I
thought it would be easier to put the public sub in that form (rather than
make all the form's subs public).

Perhaps you didn't call it correctly:

Call Forms("NameOfForm").psfrmReservations_NewReserv_Click

Or perhaps the "NameOfForm" form was not open.
Both forms must be open.
 
Thanks to you both...

Forms!frmName.functionname syntax did not work
Forms("frmName").functionname worked perfectly

-David
 
davidmound via AccessMonster.com said:
Thanks to you both...

Forms!frmName.functionname syntax did not work
Forms("frmName").functionname worked perfectly

That doesn't make sense. The two notations are equivalent; if one
works, the other one should, too. Furthermore, I just tested with a
form of my own, and

Forms!Form1.SayHi

did in fact call the Public Sub SayHi() defined the class module of
Form1, causing it to display the message "Hi!".
 
Back
Top