FindFirst打开Form

时间:2014-08-01 08:54:09

标签: vba ms-access access-vba ms-access-2007

我有一个概述表单(包含所有数字和标题的列表),其中包含一个搜索字段,可以打开另一个表单,其中包含详细信息。每个问题都有一个特殊编号,因此可以通过此编号进行识别。

现在我想使用此搜索功能直接获取详细信息(在详细信息表中只显示一个问题)。

打开表单没有问题,但findfirst命令不起作用。所以它没有显示正确的问题。

Private Sub cmdQMOSearch_Click()
' Search function - checks Nmb and Alternative Nmb

Dim SearchNmb As Long

If Len(Nz(Me.txtQMOSearch)) <> 0 Then
    SearchNmb = Me.txtQMOSearch

    If DCount("*", "tblNumber", "[Nmb] = " & SearchNmb & " OR [Nmb Alternative] = " & SearchNmb) <> 0 Then
        DoCmd.OpenForm "Nmb Adding Form", acViewNormal
        With Me.Recordset
            .Source = "SELECT * FROM tblNumber"
            .FindFirst ("[Nmb] =" & SearchNmb & " OR [Nmb Alternative] = " & SearchNmb)
        End With
        Else
            MsgBox ("There is no issue with this # yet.")
    End If

End If

End Sub

由于

1 个答案:

答案 0 :(得分:1)

使用Recordset对象使事情变得复杂。您需要做的就是打开带有WHERE条件的表单。

Private Sub cmdQMOSearch_Click()
    ' Search function - checks Nmb and Alternative Nmb

    Dim SearchNmb As Long

    If Len(Nz(Me.txtQMOSearch)) <> 0 Then
        SearchNmb = Me.txtQMOSearch

        If DCount("*", "tblNumber", "[Nmb] = " & SearchNmb & " OR [Nmb Alternative] = " & SearchNmb) <> 0 Then
            DoCmd.OpenForm "Nmb Adding Form", acViewNormal, WhereCondition:="[Nmb] =" & SearchNmb & " OR [Nmb Alternative] = " & SearchNmb
        Else
            MsgBox ("There is no issue with this # yet.")
        End If
    End If
End Sub

除非您想要提供所有记录。查看:http://baldyweb.com/Bookmark.htm