Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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 若组合框值为Sample,则搜索与Sample匹配的列_Vba_Ms Access - Fatal编程技术网

Vba 若组合框值为Sample,则搜索与Sample匹配的列

Vba 若组合框值为Sample,则搜索与Sample匹配的列,vba,ms-access,Vba,Ms Access,我正在尝试创建搜索功能,它允许用户从组合框中选择所需的列值(例如,名称),键入他们正在搜索的内容(即Alex),然后按搜索按钮,程序将选择“Name”列中包含“Alex”的所有行 这就是我到目前为止所做的,With部分在没有If语句的情况下工作,所以我想我做错了什么。lngColumn和lngRow最初设置为Long,但它给了我无效的null error用法,所以我将它们更改为variant Private Sub cmdSearch_Click() Dim strSearch As Varia

我正在尝试创建搜索功能,它允许用户从组合框中选择所需的列值(例如,名称),键入他们正在搜索的内容(即Alex),然后按搜索按钮,程序将选择“Name”列中包含“Alex”的所有行

这就是我到目前为止所做的,With部分在没有If语句的情况下工作,所以我想我做错了什么。lngColumn和lngRow最初设置为Long,但它给了我无效的null error用法,所以我将它们更改为variant

Private Sub cmdSearch_Click()
Dim strSearch As Variant, lngColumn As Variant, lngRow As Variant
Dim strValue As String
strSearch = Me.txtSearch
strValue = Me.cboSearch

If strValue = "Name" Then
    lngColumn = Me.lstTest.Column(1)
ElseIf strValue = "Occupation" Then
    lngColumn = Me.lstTest.Column(2)
ElseIf strValue = "Location" Then
    lngColumn = Me.lstTest.Column(3)
    With Me.lstTestReports
        For lngRow = 0 To .ListCount - 1
            If (.Column(lngColumn, lngRow)) = strSearch Then
                .Selected(lngRow) = True
            Else
                .Selected(lngRow) = False
            End If
        Next
    End With
End If

End Sub

只要您在

.Column(lngColumn, lngRow)
稍后,所以不能存储listbox值,而是存储列号

另外,带有Me.lstestreports的
部分不属于
If

Private Sub cmdSearch_Click()
Dim strSearch As Variant, lngColumn As Long, lngRow As Long
Dim strValue As String
strSearch = Me.txtSearch
strValue = Me.cboSearch

If strValue = "Name" Then
    lngColumn = 1
ElseIf strValue = "Occupation" Then
    lngColumn = 2
ElseIf strValue = "Location" Then
    lngColumn = 3
End If

With Me.lstTestReports
    For lngRow = 0 To .ListCount - 1
        If (.Column(lngColumn, lngRow)) = strSearch Then
            .Selected(lngRow) = True
        Else
            .Selected(lngRow) = False
        End If
    Next
End With

这应该在ms access中吗?