Query has no record

  • Thread starter Thread starter Pele
  • Start date Start date
P

Pele

I am running a form in the Hidden mode and I need to use a
message box to identify if the query linked to the form
has any record.

What is the code to use to do this. I am presently using
Setvalues in macros to copy certain values from the hidden
form. I then noticed that if the underlying query doesn't
have records, the copied value says #Error. I need to stop
the macro before it copies the #Error. Thanks.

Pele
 
Hi,
Usually you would have code similar to this:

If Me.RecordsetClone.Recordcount = 0 Then
'do something
Else
'do something else
End If
 
Hi,
I'm not sure what exactly you need the function to do.
If you just want to display a message box then:

Public Function AreThereAnyRecords(frmName As String)
If Forms(frmName).RecordsetClone.Recordcount = 0 Then
MsgBox "There are no records in this form"

End If

End Function

You can call it anything you like, you don't have to use
AreThereAnyRecords for the function name.
Just make sure you put the code in a standard module.
 
Dan,

Below is the procedure and function that I am using, and
then I call the function in a macro. Unfortunately, a
message comes up and says "Type Mismatch". Any ideas as to
what the problem is.

Pele



Public Sub Arethereanyrecords(frmName As String)
If Forms(frmName).RecordsetClone.RecordCount = 0 Then
MsgBox "Your query has returned no records....You will
need to increase your query limit."
End If
End Sub

Public Function fnArethereanyrecords(frmName As String)
Call Arethereanyrecords
End Function
 
Back
Top