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!

Can param'tr be passed in VBA (opening a report driven by param qry)

Status
Not open for further replies.

Paul7905

MIS
Jun 29, 2000
205
US
Have a report that is driven by a parameter query.

I would like to print it from a command button on a form but don't want the user to have to key in the parameter because it is a nonsensical number that the underlying code already knows.

Is it possible to pass the parameter to the Query that drives the report from VBA code?

(looking at the OpenReport "help" it appears that something can be passed as sql? does this mean that i can code the same sql that is in the parameter query here ?)

something like the following ? note, the actual value i need to pass to the query is in a global string defined as "SAVEKEY"...... it has the argument that the query needs to match on ~ i figured i could pass it as follows but it does not work ~ !

DoCmd.OpenReport stDocName, acPreview, , [ProductInfo.KEY2] = SAVEKEY


The "where" statement in the parameter query that underlies the report reads :

Where (([ProductInfo.KEY2] = [KEY]));

KEY is the name of the parameter ~

Hope it is possible to do something like this ~ driving me nuts !

BTW, thanks in advance !





 
Paul,

This really isn't too difficult. Does the underlying code know the value when you press the button? If so, my first thought (I will point out that it's only 7:20 am here1) is that you put a hidden textbox (visible = false) on the form with the value of the textbox set to the variable. This can be done a few ways.

Then your query would have a criteria that referred to the field on the form. Something like:

Forms![myForm]![txtName]

How does that sound?

Kathryn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top