Full Version: Docmd.findrecord Msgbox If No Record Found
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
RFree190
Hi All,
I have a form based on a query.
On my form, I have an unbound textbox [srch_id] that I am using to search my records.
Next to this textbox is a button. The VBA on the button (So Far) is:
CODE
DoCmd.GoToControl "CustomerID"
DoCmd.FindRecord Me![srch_id]
Me.srch_id = Null

Basically, I just want it to find a record with [CustomerID] matching [srch_id] (the unbound textbox).

This code works fine, IF, there is a matching record.
But, if there is no matching record, it doesn't do anything.

Is there some (simple) code I can add to make it display a msgbox if there are no records found?

Thanks in advance!

Rick
ace
Dim cr As Long

cr = Me.CurrentRecord

DoCmd.GoToControl "CustomerID"
DoCmd.FindRecord Me![srch_id]
Me.srch_id = Null

If Me.CurrentRecord = cr Then
MsgBox "No record found"
End If
RFree190
Awesome!!!
Thanks for your assistance!
uarulez2.gif
RFree190
Follow up question....
I have a button on my main form which performs a search of all my records and displays the results in a new Continuous View form.
On this Search Results form, there is a button which allows the user to Select one of the records, taking them back to the Main Form and displays that specific record.
This is the code on that button:
CODE
Private Sub btnReturn_Click()
On Error GoTo Err_btnReturn_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
        stDocName = "frmCustomerInfo"

    
    stLinkCriteria = "[CustomerID] = " & Me![CustomerID]
    DoCmd.Close
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    
Exit_btnReturn_Click:
    Exit Sub

Err_btnReturn_Click:
    MsgBox Err.Description
    Resume Exit_btnReturn_Click
    
End Sub


How could I modify this code to perform similarly to the code you provided above? In that when the user gets sent back to the Main Form, they are not viewing a FILTER, but instead, it uses .FindRecord?

Thanks again for your help!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.