Use Button To Open Form with Combo box prepopulated

Bloodlvst

Registered User.
Local time
Today, 14:31
Joined
Nov 27, 2018
Messages
32
Hey all,

Not at my PC until the morning, so hopefully I can be detailed enough.

I have a customer details form which shows their details. Then an order form with order details, one of which is the customer ID in a combo box.

I have a button on the customer details form, which has VBA code to open the order form (as adding a new entry). However, no matter what query I try, I can't make it pass the customer ID from the customer details form to the order form so it's already prepopulated. It's always blank. I can still click the combo box and choose a customer, but I'm trying to avoid this step.

Any ideas? I'll provide code and structure examples in the morning if required :)
 
One way would be to use OpenArgs argument.?
Then in the order form, test if a value is passed. If so, set the combo to that value.
 
Or save the customer ID as a variable then filter the order form to set the combo to that variable on form load
 
Hi. One approach I've used in the past is to use a subform for the order details form, the customer ID is entered automatically, and you won't even need a combobox for it.
 
Thanks for all the replies! I've tried some of the suggestions, but I don't think I'm getting it. Here's what I currently have for when a user clicks the "New Order" button for a customer:

Code:
 DoCmd.OpenForm "Order Form", acNormal, , "[ComboBox]='" & Me.CustomerID & "'", acFormAdd, acDialog

I am sure I'm doing something entirely wrong, but I'm not sure where my code is failing me
 
My idea was to pass the ID in OpenArgs
Code:
 DoCmd.OpenForm "Order Form", acNormal, , "[ComboBox]='" & Me.CustomerID & "'", , acFormAdd, acDialog,Me.CustomerID

and then test in the form
Code:
If NOT ISNULL(Me.OpenArgs) then
    Me.CustomerID = Me.OpenArgs
End If

You are setting a filter, but that is only if they exist?. I believe you also need another comma after the filter to skip the Where parameter.?

HTH
 
My idea was to pass the ID in OpenArgs
Code:
 DoCmd.OpenForm "Order Form", acNormal, , "[ComboBox]='" & Me.CustomerID & "'", , acFormAdd, acDialog,Me.CustomerID

and then test in the form
Code:
If NOT ISNULL(Me.OpenArgs) then
    Me.CustomerID = Me.OpenArgs
End If

You are setting a filter, but that is only if they exist?. I believe you also need another comma after the filter to skip the Where parameter.?

HTH

Thanks so much, I never really understood OpenArgs, but having my own example to work with has made it all click! :) Cheers!
 
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom