VB: Msg on opening form that contains 0 records

WalterInOz

Registered User.
Local time
Tomorrow, 02:58
Joined
Apr 11, 2006
Messages
93
Hi All,

I'd like to see a messagebox when I open a form (based on a query) that contains 0 (zero) records. I have a txtbox on the form that counts the numbers of records so I thought it'd be easiest to use that number and have the following VBA in the "on load" event:

Private Sub Form_Load()
Me.txtCount.SetFocus
If Me.txtCount = 0 Then
MsgBox "this folder does not contian any records", vbExclamation, "No records found"
End If
End Sub

I get error message 2474 (I've entered an expression with no value).
What would be a better solution?
 
at time of load, the total box won't be populated, so you can't use it. If there's no records it might be null anyway, rather than zero - i'm not sure

best thing is to count the records in the underlying source of the form, which is the recordsource (query or table)

so
if dcount("*",me.recordsource)=0 then etc

should be ok
 
YES, Wonderful!

Thank you for your quick reply.
 

Users who are viewing this thread

Back
Top Bottom