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

Print Button on Form Parameter Passing

Status
Not open for further replies.

hext2003

Technical User
Oct 9, 2006
119
US
I created a query that I use to print a report so I can print just an individual account.

I now would like to create a button on the form to print this report but it asks me to enter the account number I want to print. Is there a way to pass it the current account number I am looking at in the form?

TIA
 
You can use a Where condition:
[tt]DoCmd.OpenReport "rptReport",,,"ID=" & Me.ID[/tt]
 
Does the "ID=" have to be the exact wording of the critera? or the field name?

DoCmd.OpenReport stDocName, , , "Key=" & Me.Key

I have tried a few different ways and I keep getting a syntax error missing operator in expression '(key=992134)'
 
Is Key a text field? If so, you need some quotes:

[tt]DoCmd.OpenReport stDocName, , , "Key='" & Me.Key & "'"[/tt]
 
Yes Key is a text field

I don't get the error message any more but I still get a pop up window asking me to enter the key.

I must be missing something
 
Is Key included as a field in the report?
 
Do I need to add another field record number or something that is NOT in the report?
 
No, I'm trying to figure out why it is not working. If you have a text field Key in a table which has been used to build a report and a control called Key on the form used to call the report, then
[tt]DoCmd.OpenReport stDocName, , , "Key='" & Me.Key & "'"[/tt]

Should work. The error you are getting usually means that a field is misnamed or missing.
 
I have two Key fields in this form and report

P Key is the Parent Key
C Key is the Child Key

There is a many to one relationship between C_Key and P_Key

Do I need to have "[P_Key]='" & Me.Key & "'"

rather than just Key?
 
You need to have whatever the key is called in the report data, be that Key, P_Key or C_Key.

What you are saying is:
[tt][blue]DoCmd.OpenReport stDocName[/blue]
Open a report ...
[blue], , , "Key='" [/blue]
That has a text field called Key as part of its RecordSource ...
[blue] & Me.Key & "'"[/blue]
That matches a control on my form called Key.[/tt]
 
yep this is what I have

hmmmm

Do I need to remove the Criteria from the Query?

Thank you sooo much for your help, I'm just about ready to give up on this one.
 
Can you post the SQL for the report?

There is another possibility, which is to edit the query that the report is based on to include a reference to your form. You would put something like:

[tt]Forms![Form Name]!Key[/tt]

In the Key column of the query on the Criteria row.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top