Select 组合框选项与 Access 2013 中的 VBA

Select combo box option with VBA in Access 2013

我有一个带有组合框的表单。在组合框中选择某些选项将触发表单中的不同操作。

我希望在打开表单或转到下一条记录时自动 select 编辑第一个下拉选项。使用VBA命令ComboBox.Value = "Option1"只在组合框中输入一个字符串;这与手动单击选项不同,不会触发其他操作。

如何 select 组合框下拉列表中的选项,Access 可以像单击它一样识别它?

如果您想 update/change 使用按钮的组合框值,在 onclick 事件中

me.combobox.value = "option1"

在下面的代码中,将 Combo7 更改为您的 ComboBox 的名称。将 Filed1 更改为您的 table 的字段名称。将选项 1 更改为您的选项字符串:

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

在下面的代码中,将 Text9.Value 更改为您希望在打开表单或更改记录时执行的代码:

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

如果您有任何问题,请告诉我。

我通过设置其他答案中所述的组合框值解决了这个问题,然后调用 AfterUpdate 事件,我的操作在其中编码。该事件触发并使用我使用 VBA.

设置的 ComboBox.Value
ComboBox.Value = "Option1"
Call ComboBox_AfterUpdate