Displaying "no records found" if no record matches criteria

Danny B

New member
Local time
Today, 15:53
Joined
Jan 30, 2003
Messages
9
Hey y'all.

I'm trying to do a database for A-Level coursework, and I can't find anywhere how to get an error message to appear when a user type information in to a parameter box that is not matched in any records. It must be really simple, since many people must want to do it. All I get is a blank form, and I'm not familiar enough with access to code anything in Vis Basic yet. Basically, I just want a 'No records found' message to appear if (surprisingly) no records match.

Hope you can help :)
 
On the event causing your form to requery after setting the parameter field (a button click?), run the following code -


private sub YourButton_Click()
with me.recordsetclone
if .recordcount <1 then msgbox "No records are available"
end with
end sub

You've got the place the above subroutine code with the proper event, that is, the event with causes your form to requery.

What's "A-Level Coursework" for us Yanks?
 
Uh...I hate to sound stupid, but I'm not entirely clear on what that means.

I put in the

if .recordcount <1 then msgbox "No records are available"

line of code (although I had to take the period out), and a message box pops up saying 'no records are available'. Problem is, it comes up with that message even if records ARE displayed. I tried 'If recordcount = 0' but that still doesn't work. Do I have to put the form name before the .recordcount, and if so, what is correct terminology for entering a form name in to Vis Basic?

Thanks a lot for the help, though!

(A-Levels are the highest level of qualification before a university degree. They're the exams 17 and 18 year-olds take at college or sixth-form :) )
 
Last edited:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Macro11_Err
If (RecordsetClone.RecordCount = 0) Then
DoCmd.Close
Beep
MsgBox "There are no invoices recorded for that period.", vbInformation, "No Invoices Recorded"
End If



Macro11_Exit:
Exit Sub
 
Right, sorry about this but I still don't understand. I'm designing a database to track conveyancing cases for solicitors. All I want to do is open the central form from the switchboard. This central form is opened by clicking on a command button (is this the 'event' you mentioned?) which runs a macro to close the switchboard and open the form. It opens the form depending on the client's name.

This is the code for the macro so far:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = "CloseSwitchboardOpenFrmQryClient"
DoCmd.RunMacro stDocName
If RecordCount < 1 Then MsgBox "No records are available"

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Now, this sorta works, but the messagebox appears EVERY time the form is opened, even if records have been found.

Would any of you mind explaining exactly what you meant - like I said, I'm not hugely experienced with the Access/Visual Basic combination!

Thanks a lot...
 

Users who are viewing this thread

Back
Top Bottom