在Access 2016中,我试图创建一个VBA例程,该例程设置我的comboxbox控件的ItemData属性,但是不起作用。
我的代码:
Public Sub SetComboIndex(FormName As String, cbo As ComboBox, Index As Long)
Forms(FormName).Controls(cbo).ItemData (Index)
End Sub
并且:
Public Sub SetComboIndex(FormName As String, cbo As String, Index As Long)
Forms(FormName).Controls(cbo).ItemData (Index)
End Sub
这两种方法均无效,并返回错误#94-无效使用null异常。
我尝试了上述示例的多种变体,但均无济于事。
有人可以帮助解决这个问题吗?
编辑:感谢@ June7,我通过执行以下操作来完成此工作:
Public Sub SetComboIndex(FormName As String, cbo As String, Index As Long)
Forms(FormName).Controls(cbo) = Forms(FormName).Controls(cbo).ItemData(Index)
End Sub