Reputation: 447
I have a form with a combo box. Selecting certain options in the combo box will trigger different actions in the form.
I'd like to have the first dropdown option automatically selected when I open the form or go to the next record. Using the VBA command ComboBox.Value = "Option1"
only inputs a string into the combo box; it's not the same as clicking an option manually and does not trigger the other actions.
How do I select an option in a combo box dropdown in a way that Access recognizes it the same as clicking it?
Upvotes: 0
Views: 4561
Reputation: 447
I solved this by setting the combobox value as stated in the other answers, then calling the AfterUpdate event, where my actions are coded. The event triggers and uses the ComboBox.Value
I set using VBA.
ComboBox.Value = "Option1"
Call ComboBox_AfterUpdate
Upvotes: 0
Reputation: 10780
In the code below, change Combo7 to the name of your ComboBox. Change Filed1 to the Fieldname of your table. Change option1 to your option string:
Private Sub Form_Current()
If IsNull(Me.recordSet.field1) Then
Me.recordSet.Edit
Me.recordSet.Field1 = "option1"
Me.recordSet.Update
End If
Call Combo7_Change
End Sub
In the code below, change Text9.Value to the code you want executed when the form opens or the record is changed:
Private Sub Combo7_Change()
Select Case Combo7.Value
Case "option1"
Text9.Value = 1
Case "option2"
Text9.Value = 2
Case "option3"
Text9.Value = 3
End Select
End Sub
Let me know if you have anu questions.
Upvotes: 1
Reputation: 200
if you want to update/change a comboxbox value with the use of a button , in the on click event
me.combobox.value = "option1"
Upvotes: 2