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

Mutiple criteria for report

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
0
0
US
I am trying to run a report with the following string and I am getting a syntax type error. I believe I am missing quotes or something like that but I can't resolve this.

DoCmd.OpenReport "Time Sheet", acPreview, ,
(("[TimeCardID]=" & [TimeCardID]) _
& ("[Combowkend]=" & [WeekEnding]))

Thanks for the help
Russ
 
Russ- Try this

dim strCriteria as string

strCriteria = "TimeCardID = " & [TimeCardId] & " AND Combowkend = " & [WeekEnding]

DoCmd.OpenReport "Time Sheet", acPreview, ,
strCriteria


Scott
 
Scott,
Good thought but that didn't work. I keep getting an error message that says: Can't find the field '|' refered to in your expression. Let me clarify a couple things: first combowkend is a combobox on the form that contains dates and weekending is a field in the table. Maybe this will make a difference.

Thanks for the help..Russ
 
Russ-
OK, We're close. The syntax of the WHERE clause is:
Tablefield = Formfield. So if you have the following

This is the This is the
Table Form
field Field
strCriteria = "TimeCardID = " & [TimeCardId]
strCriteria = strCriteria & " AND WeekEnding = " & ComboWkend

Notice that the database fieldnames are within the quotes and the Form fieldnames are not. Another important thing is to make sure that neither Form field can be null.
Scott
 
thanks for all your help. That did the trick On the form and subform. Now I just need to get it to work on my report and subreport.
 
Russ-
Another way to do this is in your Report Open event write
dim frm as form
set frm = Forms!MyFormName

Me.Recordsource = "Select * from MyRecs WHERE TimeCardID = " & frm.TimeCardID & " AND WeekEnding = " & frm.ComboWkEnd

All on one line, of course. MyRecs is a table or queryname. The table or query would need to have all of the fields that you need for the report.
You can also do ranges using relational operators like:

Me.Recordsource = &quot;Select * from MyRecs WHERE TimeCardID > &quot; & frm.TimeCardID1 & &quot; AND TimeCardID < &quot; & frm.TimeCardId2 & &quot; AND WeekEnding = &quot; & frm.ComboWkEnd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top