Hi,
I am trying to create a report based on the selection from a combo box in a form.
i have some data, of which one of the fields is callled "projects". the combo box selects selects a project, and i would like to be able to open a report showing the data that belongs to the specific project on the click of a button.
i have written the code below, but the report is only ever blank. i can create a query based on the same sql statement, and it works fine. can someone help
Dim thisDB As Database, strSql, projID As String, rpt As Report
Set thisDB = CurrentDb
projID = existingProjSelector.Value
strSql = "SELECT * FROM MyTable WHERE ([PROJECT ID]='" & projID & "');"
' the following query code is commented out but works fine
' thisDB.CreateQueryDef "reportQry", strSql
'DoCmd.OpenQuery "reportQry"
' thisDB.QueryDefs.Delete "reportQry"
' why doesnt this work
DoCmd.OpenReport "Report1", acViewPreview, , strSql
i would also like to know now to change the way the data is grouped on the report etc using vb
cheers, ben
bennymacca6@hotmail.com.dontspamme

Creating and Editing Microsoft Access Reports using Visual Basic
Steve98796
Hi
Another approach is to design a report which displays all projects, then have your code open the report for editing and set the filter property equal to the value of your combo box before saving and previewing. On closing your code should remove the filter. You can copy the report and have seperate versions for your different groupings.
Just a though
ADG
Kinju
tattoo
In this case you only need to mention the WhereClause into the OpenReport command, like so:
DoCmd.OpenReport "MyReport", acViewPreview, , "[ProductID]>=" & MyProductID