Access VBA - 使用组合框(多值字段)时类型不匹配
Access VBA - Type Mismatch when working with Combo Boxes (Multi Valued Fields)
我有一个表单,一次显示一条记录,并允许通过在文本框和组合框中显示所有记录来编辑记录。其中一些是基于查找字段的组合框,其中的值是从预设列表(多值字段)中提取的。
之后,我有一个 class 模块,其中为记录中的每个字段定义了 属性(名字 属性、姓氏 属性、地址属性...你明白了)。我有一个函数,它从 class 创建一个对象,然后从表单中获取值并将它们分配给相应的 属性。这适用于大多数字段,但一旦到达第一个组合框(多选),它就会抛出类型不匹配错误。我使用的代码是:
If Me.Issue <> vbNullString Then
ProfileObj.Issue = Me.Issue
End If
'Me.Issue is the combobox on the form - this is in the forms module
'ProfileObj is the class instance
如果您想在 class 模块中查看 ProfileObj 对象的 属性:
Private ProfileIssue As String
'... other variable declarations
Property Get Issue() As String
Issue = ProfileIssue
End Property
Property Let Issue(rData As String)
ProfileIssue = rData
End Property
我也尝试过使用 Me.Issue.Value
、Me.Issue.Text
和 Me.Issue.Column(0)
来引用组合框,但其中 none 也有效。我什至尝试使用 CStr(Me.Issue)
,但无济于事。我如何获取组合框中显示的任何内容并将其分配给字符串变量?
我想通了...
我需要使用每个组合框的 .Text
属性 来读取每个组合框的文本。我曾在 If
语句中尝试过,但不是为了构建 If
语句的实际比较。代码的工作版本现在显示为:
Me.Issue.SetFocus 'You have to set focus in order to read the text, dont ask me why
If Me.Issue.Text <> vbNullString Then 'This is where my code wasn't working
.Issue = Me.Issue.Text 'I had tried it here before, but the code never got there since the line before failed
End If
我有一个表单,一次显示一条记录,并允许通过在文本框和组合框中显示所有记录来编辑记录。其中一些是基于查找字段的组合框,其中的值是从预设列表(多值字段)中提取的。
之后,我有一个 class 模块,其中为记录中的每个字段定义了 属性(名字 属性、姓氏 属性、地址属性...你明白了)。我有一个函数,它从 class 创建一个对象,然后从表单中获取值并将它们分配给相应的 属性。这适用于大多数字段,但一旦到达第一个组合框(多选),它就会抛出类型不匹配错误。我使用的代码是:
If Me.Issue <> vbNullString Then
ProfileObj.Issue = Me.Issue
End If
'Me.Issue is the combobox on the form - this is in the forms module
'ProfileObj is the class instance
如果您想在 class 模块中查看 ProfileObj 对象的 属性:
Private ProfileIssue As String
'... other variable declarations
Property Get Issue() As String
Issue = ProfileIssue
End Property
Property Let Issue(rData As String)
ProfileIssue = rData
End Property
我也尝试过使用 Me.Issue.Value
、Me.Issue.Text
和 Me.Issue.Column(0)
来引用组合框,但其中 none 也有效。我什至尝试使用 CStr(Me.Issue)
,但无济于事。我如何获取组合框中显示的任何内容并将其分配给字符串变量?
我想通了...
我需要使用每个组合框的 .Text
属性 来读取每个组合框的文本。我曾在 If
语句中尝试过,但不是为了构建 If
语句的实际比较。代码的工作版本现在显示为:
Me.Issue.SetFocus 'You have to set focus in order to read the text, dont ask me why
If Me.Issue.Text <> vbNullString Then 'This is where my code wasn't working
.Issue = Me.Issue.Text 'I had tried it here before, but the code never got there since the line before failed
End If