Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset is never null

Status
Not open for further replies.

Greaser

Technical User
Aug 1, 2001
84
CA
Hi,
When a person turns 18 years old, a letter is generateds automatically. This is the code I use to generate the letter:

Set Db = CurrentDb
strSQL = "SELECT * FROM memberInfoTbl WHERE [Age] = 18 AND [SentLetterOf18] = FALSE"
Set Rs = Db.OpenRecordset(strSQL)
If Not IsNull(Rs) Then
Rs.MoveFirst
DoCmd.OpenForm "letterOf18Frm"
End If

My problem is that the Recordset is never null even when the query is empty.

Can any one tell me how to solve this problem?
Thanks,
John
 
More explainations:
Even when the recordset is empty, the IF check passes (code goes into the If statement). I get the following error message: "Run-time error '3021'. No current record."
 
Hi Greaser!

Perhaps it's a bit late to answer to your thread, but if it could help you ... I think I have a solution to your problem : instead of isnull(rs), try rs.Nomatch.

Have a wonderful day

Flo
 
Your code modified...

' Set SQL Statement...
strSQL = "SELECT * FROM memberInfoTbl WHERE [Age] = 18 AND [SentLetterOf18] = FALSE"

' Open Recordset...
Set Rs = currentdb.OpenRecordset(strSQL)

' Check for records. If there are records, process...
If Not rc.BOF Then
Rs.MoveFirst
DoCmd.OpenForm "letterOf18Frm"
End If

The BOF property of the recordset is a quick and easy way to check to see if you have any records in an open set. By default, opening a recordset will move the cursor to the first record. If there are no records, then it will be at the BOF position. Illustration...

Recordset -> BOF - Rec 1 - Rec 2 - Rec 3 - EOF
Recordset with no records -> BOF - EOF

Hope that helps,
Gary
gwinn7
A+,Network+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top