Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问VBA-使用组合框(多值字段)时类型不匹配_Vba_Ms Access_Combobox - Fatal编程技术网

访问VBA-使用组合框(多值字段)时类型不匹配

访问VBA-使用组合框(多值字段)时类型不匹配,vba,ms-access,combobox,Vba,Ms Access,Combobox,我有一个表单,一次显示一条记录,并允许通过在文本框和组合框中显示所有记录来编辑该记录。其中一些是基于查找字段的组合框,其中的值是从预设列表(多值字段)中提取的 在这之后,我有一个类模块,它为记录中的每个字段定义了一个属性(FirstName属性、LastName属性、Address属性……你明白了)。我有一个函数,它从类中创建一个对象,然后从表单中获取值,并将它们赋给相应的属性。这适用于大多数字段,但一旦到达第一个组合框(多选),就会抛出类型不匹配错误。我使用的代码是: If Me.Issue

我有一个表单,一次显示一条记录,并允许通过在文本框和组合框中显示所有记录来编辑该记录。其中一些是基于查找字段的组合框,其中的值是从预设列表(多值字段)中提取的

在这之后,我有一个类模块,它为记录中的每个字段定义了一个属性(FirstName属性、LastName属性、Address属性……你明白了)。我有一个函数,它从类中创建一个对象,然后从表单中获取值,并将它们赋给相应的属性。这适用于大多数字段,但一旦到达第一个组合框(多选),就会抛出类型不匹配错误。我使用的代码是:

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
我还尝试使用
Me.Issue.Value
Me.Issue.Text
Me.Issue.Column(0)
来引用组合框,但这些都不起作用。我甚至尝试使用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
Me.Issue.SetFocus'你必须设置焦点才能阅读课文,不要问我为什么
如果是Me.Issue.Text vbNullString,则“这就是我的代码无法工作的地方
.Issue=Me.Issue.Text'我以前在这里尝试过,但由于前一行失败,代码从未出现过
如果结束

字符串变量应接受字母数字字符的任意组合。它将不接受Null。我从未使用过自定义类。我有一个If语句在赋值之前检查Null,所以我很确定这不是问题所在try
Me.Issue Nothing
我刚刚意识到你说组合框绑定到多值字段。这可能是问题的原因。当从这些字段中提取数据时,MVF需要特殊处理,组合框的行为与普通组合框不同。我从不使用MVF。@Mike67当我这样做时,整个函数将无法运行。。。
        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