Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox when no records found?

Status
Not open for further replies.

glxman

Technical User
Apr 19, 2007
36
GB
Hi I added the following into the Click event of a command before the Exit Sub

Code:
If RecordCount = 0 Then
    
    MsgBox "No records found?"
    
    DoCmd.Close
    
End If

It works but will also return the msgbox and close even when records are found. Please advise.

Many thanks
 
Code:
If [b]YourRecordSetVariable.[/b]RecordCount = 0 Then
    
    MsgBox "No records found?"
    
    DoCmd.Close
    
End If

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Sorry new to this coding - do I need to declare the variable? Here is the code - I added the bold bit
Code:
Private Sub cmdUmnmatchedWBSs_Click()
On Error GoTo Err_cmdUmnmatchedWBSs_Click

    Dim stDocName As String
    Dim stLinkCriteria As String


    stDocName = "frmWBSUnmatched"
    
    stLinkCriteria = "[Workstream]=" & "'" & Me![cboWorkstream] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    [b]If RecordCount = 0 Then
    
         MsgBox "No records found?"
    
         DoCmd.Close
    
    End If[/b]

Exit_cmdUmnmatchedWBSs_Click:
    Exit Sub

Err_cmdUmnmatchedWBSs_Click:
    MsgBox Err.Description
    Resume Exit_cmdUmnmatchedWBSs_Click
    
End Sub

Thanks
 
Replace this:
If RecordCount = 0 Then
with this:
doEvents
If Forms(stDocName).Recordset.RecordCount = 0 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top