Creating reports from record set

G

Gary Dolliver

Hi all,
I am attempting to create a tool that will select specific records,
determine whether there is an email, and depending on that will either email
or create a printable report. Here is what I have:
Dim rst1 As DAO.Recordset
Set rst1 = CurrentDb.OpenRecordset("CS_HOLD_Contact_1")
If rst1.RecordCount > 0 Then
rst1.MoveFirst
'check for email
Do Until rst1.EOF 'End of file
If IsNull(rst1!ShipTo_Email) Then
DoCmd.OpenReport "CS_Hold_Attempt_1", , , "Order_ID=" &
rst!Order_ID
rst1.MoveNext
Else
...do something...
rst1.MoveNext
End If
Loop
...do something...
Else
MsgBox "No records to process for 1st notification!", vbInformation
End If

The problem is occurring in the DoCmd.Open Report line, something with my
criteria (the Else works great) - I keep getting a 424 Object Required error
- The report is fed by the same query that is feeding the recordset. I have
a field in the report called Order_ID as well. I have been staring at this
for some time and cannot make any sense of it. Help is appreciated, thanks!
-gary
 
C

Carl Rapson

Gary Dolliver said:
Hi all,
I am attempting to create a tool that will select specific records,
determine whether there is an email, and depending on that will either
email
or create a printable report. Here is what I have:
Dim rst1 As DAO.Recordset
Set rst1 = CurrentDb.OpenRecordset("CS_HOLD_Contact_1")
If rst1.RecordCount > 0 Then
rst1.MoveFirst
'check for email
Do Until rst1.EOF 'End of file
If IsNull(rst1!ShipTo_Email) Then
DoCmd.OpenReport "CS_Hold_Attempt_1", , , "Order_ID=" &
rst!Order_ID
rst1.MoveNext
Else
...do something...
rst1.MoveNext
End If
Loop
...do something...
Else
MsgBox "No records to process for 1st notification!", vbInformation
End If

The problem is occurring in the DoCmd.Open Report line, something with my
criteria (the Else works great) - I keep getting a 424 Object Required
error
- The report is fed by the same query that is feeding the recordset. I
have
a field in the report called Order_ID as well. I have been staring at
this
for some time and cannot make any sense of it. Help is appreciated,
thanks!
-gary

I can't see any obvious problems. The only thing that comes to my mind is,
are you certain there's a non-Null value in Order_Id? If you hard-code a
value into the OpenReport call, does it work? And just to ask, are you
absolutely certian the field in the recordset is named Order_Id? Could it
possibly be OrderId or even Order Id (with a space)?


Carl Rapson
 
G

Gary Dolliver

Hi Carl,
Thanks for posting back. After sleeping on it and coming back I found my
issue. I noticed in the report where condition, I was calling the recordset
incorrectly - it should be rst1! where I had rst! Arrrggghh!!!
Thank you so much again for the reply
-gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top