访问过滤器仅使用子表单

时间:2013-08-22 12:47:08

标签: ms-access-2007 access-vba

我在一个表单上有一个搜索框,它通过OrderID(ex 305321)在结帐和订购表单上找到记录,第二个我刚刚添加到表单中以查找搜索FLID值的地板产品(来自FLID00005)然而,第二个只会返回一个新的记录,即使我搜索的数据存在,当我在其上使用输入功能时,它会要求输入参数值,如果我输入相同的值,它在搜索框中正确运行。

订单搜索表单的代码:

    Private Sub cmdFindbyOID_Click()
    If IsNull([FindByOIDSearchBox]) Then
        MsgBox "You must Enter a Order ID", vbInformation, "Error"
        Exit Sub
    End If
    Me.Filter = "(([Orders In Progress Query].OrderID = " & FindByOIDSearchBox & "))"
    Me.FilterOn = True
    Me.[Orders All Details Subform].Requery
End Sub

Private Sub FindByOIDSearchBox_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        cmdFindByOID.SetFocus
    If IsNull([FindByOIDSearchBox]) Then
        MsgBox "You must Enter a Order ID", vbInformation, "Error"
        Exit Sub
    End If
    Me.Filter = "(([Orders In Progress Query].OrderID = " & FindByOIDSearchBox & "))"
    Me.FilterOn = True
    Me.[Orders All Details Subform].Requery
    End If
End Sub

地板产品的代码形式:

Private Sub cmdFindbyFLID_Click()
    If IsNull([findByFLIDSearchBox]) Then
        MsgBox "You must Enter a Flooring ID", vbInformation, "Error"
        Exit Sub
    End If
    Me.Filter = "(([Flooring Products Query].FLID = " & findByFLIDSearchBox & "))"
    Me.FilterOn = True
End Sub

Private Sub FindByFLIDSearchBox_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        cmdFindbyFLID.SetFocus
    If IsNull([findByFLIDSearchBox]) Then
        MsgBox "You must Enter a Flooring ID", vbInformation, "Error"
        Exit Sub
    End If
    Me.Filter = "(([Flooring Products Query].FLID = " & findByFLIDSearchBox & "))"
    Me.FilterOn = True
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

FLID包含字符。因此,您的参考需要在单引号内。

Me.Filter = "(([Flooring Products Query].FLID = '" & findByFLIDSearchBox & "'))"