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

using the docmd.openreport [wherecondition]

Status
Not open for further replies.

MrsMope

Technical User
Oct 18, 2004
125
US
Good afternoon,
I have a query supplying data to a report, however I want to add a where clause into this. I have a small form set up with three buttons, I have the value of the button stored in a variable, I pass that variable into the docmd openreport statment, however the where clause does not seem to be working here is docmd statment:
Code:
Private Sub cmdTruss_Click()
On Error GoTo Err_cmdTruss_Click
    Dim strType As String
    Dim stDocName As String
    Dim strWhereCondition As String
    strWhereCondition = "[Type] ='Truss'"
    stDocName = "JobTime"
    DoCmd.OpenReport stDocName, acPreview, , strWhereCondition, acWindowNormal
The query behind the report is simply
Code:
SELECT * FROM tmpJobTime
 
MrsMope,

There is a great example of this in the Northwind sample database. View the code on the print button (on click event).

I hope this helps.

 
MrsMope,
What do you mean by "the where clause does not seem to be working"? We can't see your data or your report or any error messages you might be getting.

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]
[blue]Ask me about my grandson, get a grand answer.[/blue]
 
dhookom,
I have the parameters for the where clause, however all records still display on the report.
 
Try place a text box in the Report Header section
Control Source: [Filter]
Review this text box after opening the report to see what the report's current filter is.

Have you confirmed the expected code is being run? Try add a line to your code
stDocName = "JobTime"
MsgBox "Where Clause: " & strWhereCondition
DoCmd.OpenReport stDocName, acPreview, , strWhereCondition, acWindowNormal


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]
[blue]Ask me about my grandson, get a grand answer.[/blue]
 
FYI~~~~~~~~~~~~~~~~~
I changed my source property for the report to a query, I had the actual statement in there. IE: SELECT * FROM tmpJobTime. I created a query that does the same thing, now my reports pulls correctly!
Thanks,
MrsMope
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top