Any help here would be great

Danny B

New member
Local time
Today, 05:58
Joined
Jan 30, 2003
Messages
9
Hey all,

I posted a few days ago in an attempt to try a find out how to display a 'No records found' message when a query turns up no criteria-matching results. I got two replies. Unfortunately, neither worked for me (although I'm sure it did for them).

Basically, a form (displaying the query's results) is opened via a command button on the system's switchboard. The button runs a macro to close the switchboard and open the form. The query form is called FrmQryClient, and the query itself is simply QryClient.

This is the current code used by the command button:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = "CloseSwitchboardOpenFrmQryClient"
DoCmd.RunMacro stDocName
If (Form_FrmQryClient.RecordCount = 0) Then MsgBox "No records are available"

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Because I am fairly unfamiliar with Visual Basic, I am finding it hard to use the terminology. At present, this code brings up the message 'Object required'. If I do not specify the Form_FrmQryClient then the MsgBox is displayed every time the form is opened, whether results have been found or not.

Any ideas would be greatly appreciated!
 
Danny B said:
DoCmd.RunMacro stDocName
If (Form_FrmQryClient.RecordCount = 0) Then MsgBox "No

Have you tried a Dovents between the DoCmd and the If?
Sometimes that works to let the system "catch up" with the code.

DoCmd.RunMacro stDocName
DoEvents
If (Form_FrmQryClient.RecordCount = 0) Then MsgBox "No
 
Use DCount:

stDocName = "CloseSwitchboardOpenFrmQryClient"
DoCmd.RunMacro stDocName
If DCount("*", "QryDOB") = 0 Then
MsgBox "No records found"
End If

RV
 
You need to put the code example I gave you in the OnOpen event of the form you are opening. Please continue with an existing post so members know what has already been suggested
 

Users who are viewing this thread

Back
Top Bottom