Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event button open form, AND start VBA code on form 2

Status
Not open for further replies.

Phil4tektips

Technical User
Jul 18, 2005
89
GB
I have a button on a form1 to open another form2.

I would like to have this button open the form2 AND start some VBA code that is assigned to a button on form2.

When I just put in code to start the VBA routine, it was looking for the code on form1 when it is actually on form2.

How can I get this to work?

Many thanks all.

-Phil4tektips-
 
The form is opened at other times aswell. I dont require to happen everytime it is opened, just when this button on the other form is clicked.

Cheers
 
Pass something in the openargs, and test for it

[tt]docmd.openform "myform",,,,,,"blah"[/tt]

then on the receiving side

[tt]if len(me.openargs)>0 then
' call the code
end if[/tt]

Roy-Vidar
 
You should still use the Open event.
In the Docm.openform command on the calling form use the openargs parameter to pass a value(e.g. "Y") to the called form.
In the open event of the called form test the openargs value
If me.openargs = "Y" then
buttonname_click
else
' do nothing
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top