how to give a parameter to a query

A

Alex

I'm using the following to transfer data from MS Access to
Excel:

DoCmd.OutputTo acOutputQuery, _
"Query1", acFormatXLS, _
"ExcelFile.xls"

The Query1 is taking some value the exchange rate for
calculations. Before, I was using a textbox on a form to
give the Query1 this value. When the form is being opened
the fnEchangeRate function is being run and the value is
being assigned to the textbox.

How could I give the value from the function to the Query1
not through the textbox but (if it's possible) through a
parameter before running this DoCmd.OutputTo ...

Thanks
 
P

peter walker

Don't use a parameter query.
Alter the query definition - change the SQL

Sub cq()
Dim qd As QueryDef
Set qd = CurrentDb.QueryDefs("query1")
qd.SQL = "Select * from table1 " & _
"where somevalue ='" & LitteralValue & "'"
DoCmd.OutputTo acOutputQuery, _
"Query1", acFormatXLS, _
"c:\ExcelFile.xls"
End Sub

peter walker
 
A

Alex

Thanks a lot, Peter.
-----Original Message-----
Don't use a parameter query.
Alter the query definition - change the SQL

Sub cq()
Dim qd As QueryDef
Set qd = CurrentDb.QueryDefs("query1")
qd.SQL = "Select * from table1 " & _
"where somevalue ='" & LitteralValue & "'"
DoCmd.OutputTo acOutputQuery, _
"Query1", acFormatXLS, _
"c:\ExcelFile.xls"
End Sub

peter walker




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top