Form Combo Box

speakers_86

Registered User.
Local time
Today, 18:17
Joined
May 17, 2007
Messages
1,919
I have a combo box based on my customer table. If the entry is a new customer, there is a button right next to the combo that when clicked, opens up the customer form. I have 2 quesitons.

When the form opens, how can I get it to open in add mode? I found this link, which should answer this question, but I havent tried yet.
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_23118830.html

When this form is open, either a new customer can be entered, or the user can find the customer using the search feature in the customer form. Once one of these 2 things are done, the user will close the customer form. How can I get the combo box to move to the record that was showing when the customer form was closed?
 
Use the OpenArgs on your open form command behind your button, it should look something like this;

Code:
DoCmd.OpenForm "FRM_Name", , , , , , "New"

The OpenArgs could be any word you choose, but it makes a lot of sense to use "New" as you will know what the OpenArg is supposed to achieve.

Then on the "On Load" event, form of the form that you are opening test the OpenArg;

Code:
If OpenArgs = "New" Then
        DoCmd.GoToRecord acDataForm, "FRM_Name", acNewRec
End If

To achieve the last part, once again test the OpenArgs and then set the value of your combo box accordingly.
 
So that would open the form in add mode right? That wouldnt bring any value back to the combo box would it?
 
You can control how the form opens as part of the DoCmd. Use acFormAdd

Code:
DoCmd.OpenForm FRM_Name, , , stLinkCriteria, acFormAdd, , "New"

As for passing the value back to the combo you would, as I said before, you need to test the OpenArgs in the on close event of the Add Details Form, and set the value of the Combo as the value you have just added.

Code:
If OpenArgs = "New" Then
        Forms!FRM_Name!ComboName.Requery
        Forms!FRM_Name!ComboName.Value = Me.ClientID
End If

You may want to do a check that your Combo doesn't already hold a value before you set it's value to make sure you are not overwriting an existing record.
 

Users who are viewing this thread

Back
Top Bottom