jberv534
asked on
Change Query SQL in VBA
I am using a subreport to display a list of all tasks based on a project ID. I would like to use a list box to allow show selected tasks (based on a field in the list) by using .requery
I would like to change the query that is the source of the subreport.
subreport name is "subProjectTasks"
query name is "ProjectTasks Query"
Any help, as always, is much appreciated.
Jeff
I would like to change the query that is the source of the subreport.
subreport name is "subProjectTasks"
query name is "ProjectTasks Query"
Any help, as always, is much appreciated.
Jeff
ASKER
Arji - thanks for the reponse. I did not make myself clear about something:
I want to change the sql statement that ProjectTasks Query uses by adding a WHERE statement.
Jeff
I want to change the sql statement that ProjectTasks Query uses by adding a WHERE statement.
Jeff
The Column(0) assumes that in your list, column 0 is the project ID. When you set a RecordSource, it works the same as a requery.
[subProjectTasks].[Report] .RecordSou rce = "select * from ProjectTasks where [project ID]=" & [YourList].Column(0)
Also you can open a report with the criteria in the DoCmd method. Assuming your report's record source is "ProjectTasks":
DoCmd.OpenReport YourReport, acViewPreview, , "[project ID]=" & [YourList].Column(0)
I think this method is better in that you can set criteria dynamically when you open the report
Hope I understood what you wanted....
[subProjectTasks].[Report]
Also you can open a report with the criteria in the DoCmd method. Assuming your report's record source is "ProjectTasks":
DoCmd.OpenReport YourReport, acViewPreview, , "[project ID]=" & [YourList].Column(0)
I think this method is better in that you can set criteria dynamically when you open the report
Hope I understood what you wanted....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
[subProjectTasks].[Report]
or
Me.[subProjectTasks].[Repo
Not sure if you really need the Me. but it doesn't hurt either. :-)