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!

Compond criteria with DoCmd.OpenReport

Status
Not open for further replies.

tamus121

Technical User
Mar 19, 2007
38
GB
Hi first time posting. I have been struggling with this in various forms for days. When previewing a report this works :-
[DoCmd.OpenReport stDocName, acPreview, , "Inspection_Type = Forms!InsReports.Reporttype1"]

but I want to base the report on various criteria depending on users options selection. I am using If.. Then.. Else If .. Then.. Else.. End If to select the report needed. When I join two criteria with And I get "Type Mismatch" as below :-

[DoCmd.OpenReport stDocName, acPreview, , "InspectionType = Forms!InsReports.Reporttype" And "Inspector = Forms!InsReports.InspCode1"]

Any ideas as to what I am doing wrong please
tamus
 
It would help if you provided your data types. I always create a strWhere variable to build prior to the DoCmd.OpenReport method. Assuming InspectionType is numeric and Inspector is text, try:
Code:
Dim strWhere as String
strWhere = "InspectionType = " & Forms!InsReports.Reporttype & _
   " And Inspector = """ & Forms!InsReports.InspCode1 & """"

DoCmd.OpenReport stDocName, acPreview, , strWhere
If the code is running in Forms!InsReports then simply use:
Code:
Dim strWhere as String
strWhere = "InspectionType = " & Me.Reporttype & _
   " And Inspector = """ & Me.InspCode1 & """"

DoCmd.OpenReport stDocName, acPreview, , strWhere


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Both are Text but I have amended your suggestion to suit and as the code is in the Forms!InsReports I have taken on your second method. thanks very much, it works well, I have 3 frames with options and now have a possible total of 240 different reports to view.
Tried to put my own code in display box as you have done but I have missed something, (a quick pointer please)
tamus
 
You can use TGML to display colors, font styles, and other stuff. Click the Preview Post button and find a link on TGML help.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top