Question

I have an overview form (list with all numbers and titles) which has a search field which opens another form with detailed information to an issue. Each issue has a special number so it can be identified by this number.

Now I want to use this search function to get directly to the detailed information (at the detailed information form just one issue is shown).

There is no problem with opening the form but the findfirst command does not work. So it doesn't show the right issue.

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

Thanks

Was it helpful?

Solution

You are complicating things by using the Recordset objects. All you need to do is open the Form with the WHERE condition.

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

Unless you want to have all the records available. Check out: http://baldyweb.com/Bookmark.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top