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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd openform

Status
Not open for further replies.

fludan

Technical User
Feb 1, 2002
41
US
Hi

I have a form called customer with a field called customerID and I have another form called orders with a field called customerID and an autonumber orderID.
What I am trying to do is when the form customer is open i would like to be able to press the order button and have the order form open with the cutomer id from the form customer.
I tried this:
Private Sub Orders_Click()

DoCmd.OpenForm "orders", , , "[customerID] = Forms![Customer].form![customerID]"

End Sub
thanks
frank
 

Open your form:
Private Sub Orders_Click()
DoCmd.OpenForm "orders"
End Sub

Then place the following code in the orders form:
Private Sub Form_Load()
ordercustomerid.Value = Forms!Customer!customerid
End Sub
*substitute the name of your field from the orders table
with ordercustomerid.value*

this will extract the customerid form your customer form and insert it into the order form customerid field ...


HTH
 
Frank, my first response works if you are opening the orders form to add a new order, however if your trying to open the orders form with pre-existing records try changing your code to the following

Private Sub Orders_Click()

DoCmd.OpenForm "orders", , , "[customerID] = '" & Me![customerID] & "'", acFormEdit

End Sub


 
BucksFan25 (or anyone):

This would -almost- work for what I need to do. I need this same ability (open a new form with one field filled in from this form) but I don't always want this to happen. Sometimes I will be opening this form just to browse records. Is there code that can go on the button that will set this? or could I just put the form_load code on the button?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top