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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordsource as Report Criteria

Status
Not open for further replies.

NMiller007

Programmer
Nov 15, 2006
65
US
I am trying to use a recordsource to cycle through different report criteria. I need the report to display for every user and then this report will be e-mailed.

Here is my code:
Code:
Dim db As DAO.Database
Dim rsUsers As DAO.Recordset
Dim UsersSQL As String
Dim WhereCriteria As String
Dim SaySomething As String
    
UsersSQL = "SELECT * FROM Users;"

Set db = CurrentDb
Set rsUsers = db.OpenRecordSet(UsersSQL)
   
Do Until rsUsers.EOF
 SaySomething = rsUsers!user_name
 MsgBox (SaySomething)
        
 WhereCritera = "[user_name] = " & SaySomething
 MsgBox (WhereCriteria)
    
 DoCmd.OpenReport "InspectionSpreadsheet", acViewPreview, "", WhereCriteria
 rsUsers.MoveNext
Loop
rsUsers.Close

SaySomething stores each record, but when I try and combine them, WhereCriteria is Null (the MsgBox is blank). When this is run, I get a MsgBox that displays the first record, then a MsgBox that is blank. Then the next record and blank and so on. The report comes up, but displays every record and doesn't reload each time.

What am I doing wrong? Is there another way I'm supposed to reference each member of the recordset? Is there another way to do this altogether?

Thank you.

 
Okay, now I have eliminated the WhereCritera and it is working.

I don't know what was going on with that variable, but I guess I wasn't that attached to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top