detect when no records exist

Shawny

Registered User.
Local time
Today, 14:05
Joined
Apr 15, 2000
Messages
64
I need a macro condition that can detect if a Query I ran has any records. I am trying to prevent duplicate records being entered. My thought was to run a find dup. Q after 3 or 4 fields had been entered.
I also have a linked form that I have set to GoToLastRecord when it opens. It works, except when there are no records ( I have the allow additions property set to no). Then I get error messages becaues there are no records to base the macro on. If I could detect no records, I could eliminate the error stuff. I do not know VBA (Yet).
 
For this type of case I think you will need to use VBA. For no records you will need to be able to return the Record Count first of your query and Second of your form.

To see if a query has any records.

Public Function GotRecords(ByVal stSQL) as Boolean
On Error Resume Next
Dim rst as Recordset '(2000 it is Dao.Recordset)
set rst = Currentdb.OpenRecordset(stSQL)
rst.MoveNext
if Err <> 0 then
GotRecords = True
Else
GotRecords = False
End if

Send your Query to this Function as follows.
If GotRecords("QueryName") = True then
'It has a record now what?
Else
'No Record now what?
End if

On your form. add this code to the Form_Open Event.
if Me.RecordsetClone.RecordCount > 0 then
'Form Has Records. Now What?
Else
'Form Does Not Have Records. Now What?
End if

P.S. I would spend time to learn VBA as the Macro environment is very limited and the VBA environment is more open for calculations.


[This message has been edited by Travis (edited 04-17-2000).]
 

Users who are viewing this thread

Back
Top Bottom