call a sub from another form or module

threeo2

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2003
Messages
31
I have a form for entering new customer information, "Form 1". when you click the finish button on Form 1 the code closes Form 1, opens Form 2 so you enter the customer's ordering info. What I want to do is after Form 2 is opened remotely from Form 1 run the ENTER NEW ORDER button's private sub so the person entering the order does not have press it manually.

So in a nut shell what i want to do is from form 1 call or run a sub from form 2 after form 2 has been opened form 1 and form 1 has been closed.
Don't know where to start!
 
In VBA using the following code to open the form which adds a blank record upon loading of the form.

Code:
DoCmd.OpenForm "Form2", , , , acFormAdd

Andy
 
Thanks Andy, that did the trick on opening the form, now I need to know how to call the sub from another form.
 
Hi,

This should do the trick:
Forms!form1.EnterNewOrder_Click

However, you will need to make the PRIVATE sub into a PUBLIC sub for this to work, I think.

(A better coding technique would be to create a separate (public) Enter New Order function in the code for form2 and call this function from both places.

Hope that helps,
Keith.
 
What code are you running in the private sub?

The only reason I ask is because if I have read you post you wanted to add a new order, the code I supplied should do the trick. Also you wouldn't want to open the form2 on it's own so transfer the code to the form Load event.

Because if you opened the form2 on it's own, if the db is designed correctly then you shouldn't/wouldn't be able to enter the order details without first entering the customer details.
Otherwise follow Keith's advise to change it to a public function.

Let me know what you decide.
Andy
 
Andy,

I have some measures in place that keep users from editing old orders. So the ENTER NEW ORDER Button sets the AllowEdits property of the form to true. When they finish the order the user hits the FINISH button that sets the AllowEdits property back to false. I have a similar scenario for orders on hold also.

THNX
 
Have you used Keith's suggestion by changing the private sub to public?

Andy
 
YES, matter of fact I just tried that and it works great. I made a public sub that I call from both forms. THANKS GUYS!
 

Users who are viewing this thread

Back
Top Bottom