Calling a sub in a different form in VBA

CadMonkey

Misplaced But Useful
Local time
Today, 23:48
Joined
May 19, 2004
Messages
47
Hi,

I wander if anyone can help? Multiple web searches have turned up nothing!

I would like to call a sub that is defined in form1. However, I am trying to call it from another form: form2. I.E In vb if use this code:

call sub1

It says no sub defined, beacuse I'm calling it from form2.
(The forms are in the same DB)

if I try:

call form1.sub1... it just doesn't work¬

Can anyone suggest a method?

Many thanks,

Simon
 
Put the code out in a Module and call it from both forms.
 
please see next post....
 
Last edited:
CadMonkey said:
thank pdx man,

sorted now
oops! No still need to access one forms sub from another...

the reason is I'm trying to set the focus to a form so I can sort using this code:

Work_Ref.SetFocus
DoCmd.RunCommand acCmdSortAscending

but I can't set the focus on the Work_Ref field from another form- that's why this sub is in form1 (and does sort the form correctly)

any more ideas??
 
The scope of a form's code module is limited to that form. You can do this in a module, you just need to fully qualify its reference. [Forms]![Frm_One]![Work_Ref]
 

Users who are viewing this thread

Back
Top Bottom