If there is no record to show

johndoomed

VBA idiot
Local time
Today, 01:12
Joined
Nov 4, 2004
Messages
174
Hi all! Need your help again!

I'm having a problem in my CRM application with forms that contains no record.

On example is a form for printing invoices. When there is no new invoices to print, this form opens without any records - causing errormessages etc.

I have the same problem with a "fast open" function on my main-menu form, here users can type in the ID for costumers, tasks, projects, invoice, etc. If the ID is incorrect, there is no record to show, and a lot of confiusion for the users.

I've tried searching for a solution online, and tried to "hack" the problem myself with different errorhandlers, but without luck.

Is there a simple way (Or just a way) to check if there is actually a record to display when the form opens? And if not, show a msgbox and then close the form?

Thanks for all you help!
 
In the open event of the form you can check for an empty RecordSet.

If Me.RecordSet.RecordCount = 0 Then
MsgBox "Sorry but there are no records to display!"
Cancel = True
End If

...which will cancel the open event.
 
RuralGuy: Thanks! This seems to work, but I get "Runtime error: 2501 - (Translated from norwegian) Operation "OpenForm" was canceled."

Just fix this with a errorhandler?

Edit: The post by Rich answered this! Thanks to both!
 

Users who are viewing this thread

Back
Top Bottom