I am trying to pass values selected from a list box to a report named 'CountyReport'. In my report, I have the following statement as my datasource:
SELECT [suggested-build/site].project_id, [suggested-build/site].[req-build_name], [suggested-build/site].[req-county], Project.project_mgr
FROM (Company_Info INNER JOIN Project ON Company_Info.company_id = Project.company_id) INNER JOIN [suggested-build/site] ON Project.project_id = [suggested-build/site].project_id
ORDER BY [suggested-build/site].[req-county], [suggested-build/site].[req-build_name];
On a form I built, I have my list box that the user can select counties from. After they have selected the appropriate counties, they click on a button to run the report.
When they click on the button located on this form, I'm creating a WHERE statement.
Example: " WHERE [suggested-build/site].[req-county] = 'SMITH' OR [suggested-build/site].[req-county] = 'JONES' "
After the WHERE statement has been created, I am using the following code to run the report:
----------------------
' This variable holds the name of the report
Dim stDocName As String
' The string strSQL holds the WHERE statement that I created.
stDocName = "CountyReport"
DoCmd.OpenReport stDocName, acViewPreview, , strSQL
----------------------
When the DoCmd is executed I receive a Run-Time error '3075'. It says "Syntax error (missing operator) in query expression '( WHERE [suggested-build/site].[req-county]= 'ADAMS' OR [suggested-build/site].[req-county]= 'JONES')'.
My questions are:
1. Is my DoCmd statement correct?
2. Can I pass a WHERE statement to a report? I assume that I can after looking at the help documentation for OpenReport.
Thanks!
SELECT [suggested-build/site].project_id, [suggested-build/site].[req-build_name], [suggested-build/site].[req-county], Project.project_mgr
FROM (Company_Info INNER JOIN Project ON Company_Info.company_id = Project.company_id) INNER JOIN [suggested-build/site] ON Project.project_id = [suggested-build/site].project_id
ORDER BY [suggested-build/site].[req-county], [suggested-build/site].[req-build_name];
On a form I built, I have my list box that the user can select counties from. After they have selected the appropriate counties, they click on a button to run the report.
When they click on the button located on this form, I'm creating a WHERE statement.
Example: " WHERE [suggested-build/site].[req-county] = 'SMITH' OR [suggested-build/site].[req-county] = 'JONES' "
After the WHERE statement has been created, I am using the following code to run the report:
----------------------
' This variable holds the name of the report
Dim stDocName As String
' The string strSQL holds the WHERE statement that I created.
stDocName = "CountyReport"
DoCmd.OpenReport stDocName, acViewPreview, , strSQL
----------------------
When the DoCmd is executed I receive a Run-Time error '3075'. It says "Syntax error (missing operator) in query expression '( WHERE [suggested-build/site].[req-county]= 'ADAMS' OR [suggested-build/site].[req-county]= 'JONES')'.
My questions are:
1. Is my DoCmd statement correct?
2. Can I pass a WHERE statement to a report? I assume that I can after looking at the help documentation for OpenReport.
Thanks!