How do you select a value in a combobox?

Jack_Maloney

Registered User.
Local time
Today, 23:12
Joined
Dec 22, 2010
Messages
13
Hi,

Basically, I wish to automatically select a combobox value when the form loads based on a value selected in another form.

So just to give you an overview of what my forms look like I have a form called 'View_Sales_Orders_frm' with a combo box which we'll call combo1 for now. If the user selects a value from combo 1 and then selects the 'New Sales Order Log' button it opens another form called 'New_Sales_Order_frm' with another combo box which we'll call combo2. I basically want the value in combo2 to be equal to that selected in combo1 when the form first loads.

However, I cant get the value of combo2 to automatically match that of combo1. Here is the code I have so far. I may well be on the wrong track here so would much appreciate it if someone could point out what im doing wrong!

Private Sub New_Sales_Order_Log_btn_Click()
Dim strProjectNameField As String
Dim strWhere As String

strProjectNameField = "[combo2]"
'Build the filter string
If Me.combo1.Value <> vbNullString Then
strWhere = strWhere & "(" & strProjectNameField & " = " & Me.combo1.Value & ")"
End If
'Debug.Print strWhere

DoCmd.Close acForm, "View_Sales_Orders_frm"
DoCmd.OpenForm "New_Sales_Order_frm", , strWhere
DoCmd.GoToRecord , , acNewRec

End Sub
 
When you open your second form you can use the Forms OnLoad event

me.Combo2 = Forms("Form1")("Combo1")
 
Hi,

Thanks for the response. That works if the combo box is not bound to another field. However, as soon as I associate a value with the 'Control Source' option of the combo box it wont automatically select the value.

Is there anyway around this problem? i.e. so that when the user adds the record to the database, the value which is automatically selected in the database is added.
 

Users who are viewing this thread

Back
Top Bottom