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

To open report through Query

Status
Not open for further replies.

yummy7

Technical User
Jun 2, 2006
195
CA
I have this code. Which modifies Query2 and then open it in preview format. I want to make this query datasource of a report. I want to show this modifies query through report.Is it possible

CurrentDb.QueryDefs("Query2").SQL = "SELECT " & strList & " from Store_t where " & GetCriteria()
DoCmd.OpenQuery "Query2", acViewPreview, acReadOnly
Any suggestion is most appreciated.
 
Why not simply have the RecordSource property of the Report set to Query2 ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanx for response.
I am getting error "The report name 'rpt Store' you entered is mispelled or refer to a report that isnt open or doesnt exist." So please tell me should I make the report through wizard or design view.How should be the report.Why its giving error?
CurrentDb.QueryDefs("Query2").SQL = "SELECT Snumber from Store_t where " & GetCriteria()
Reports!rptStore.Recordset = "Query2"[b/]
DoCmd.OpenReport Reports!rptStore , acViewNormal, , , acDialog
 
I did but it is showing empty report.Actually there is no field in report.I only set its recordset field = Query.Where i am going wrong.
 
Go to the Design view of your report and put some fields on it. Add a textbox control and set its Control Source property to your field (Snumber).
 
Sorry rjoubert,it not showing data according to Query2. I put some textBoxes and only give control source to Snumber.But You also know that fields of Query2 are always changing like
CurrentDb.QueryDefs("Query2").SQL = "SELECT " & strList & " from Store_t where " & GetCriteria().
So report should show Query2 but what about textBoxes in Report.If they are in report so they also should be selcted in criteria. Its not making sense.
I only want that report should show whatever is in Query2.
 
Actually the following code was working excellent and meet my criteria.
CurrentDb.QueryDefs("Query2").SQL = "SELECT " & strList & " from Store_t where " & GetCriteria()
DoCmd.OpenQuery "Query2", acViewPreview, acReadOnly

But this query opens behind all the forms.So that i cnnot see it.I want it to be focused when it is openend,Infront of user.How I can set focus on Query2.
Please help me in this regard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top