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

Report Condition (Where) 2

Status
Not open for further replies.

janetlyn

Technical User
Jan 29, 2003
516
US
I have a form (frm-ParentMainForm), with a subform (frm-ChildPLHours) holding a label (Label9).

I would like to click on Label9, which would open a report in print preview. The report is based on a query (QRY-ProjectHrsSearch) which has a parameter asking for "What project number would you like?" When Label9 is clicked I want it to match the Project# that is in the current record in frm-ParentMainForm with the Project# as the parameter. Below is the code I wrote:

DoCmd.OpenReport "RPT-ProjectHrsSearch", acViewPreview, , [QRY-ProjectHrsSearch].[Project#] = [frm-ParentProjectMain].[Project#]

However, I am getting an error because it does not like one of my names. They are all right, but I am sure my syntax is wrong. Any suggestions? Thanks, JL
 
In your query, replace this:
[What project number would you like?]
By this:
[Forms]![frm-ParentProjectMain]![Project#]
or
[Forms]![frm-ParentMainForm]![Project#]
as I'm confused with your form names
And in the Click event procedure of the label, simply do this:
DoCmd.OpenReport "RPT-ProjectHrsSearch", acViewPreview

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Take a look at using the WhereCondition parameter in the line of code that opens your report. If you make your QRY-ProjectHrsSearch the data source for your report, and then set the WhereCondition equal to your Project# it should give you the results you want.

Code Example: DoCmd.OpenReport "RPT-ProjectHrsSearch", acViewPreview, WhereCondition:=[frm-ParentProjectMain].[Project#]

 
PHV, you have just helped me tremendously today. It worked. I really appreciate all your help. If I could give you more than one star I would. Have a wonderful day, JL
 
bbbum, Since PHV got me rolling I not going to break his hard work. However, now that I look at it again, I did screw up a name. It is ProjectNo not Project#, which is how I had it when I first started this DB. When I looked at the Help in VB it said "a Where condition without having to use the word Where". So, I didn't think I needed to. Glad you showed me the right way, though. Have a wonderful day also, JL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top