Passing a variable as the parameter for a query 
Author Message
 Passing a variable as the parameter for a query

How do I pass a variable to be used as a parameter in a query?

The only way I can get this to work is to first assign the variable to a
control (e.g., a textbox).  And then pass the value of the control to the
query.

Is there a way to pass the variable to the query directly, avoiding the
extra step of having to first assign it to a control and then referencing
the control value as the parameter?

Thanks for any ideas?
Dave
--------
David R. Frick & Co., CPA
http://www.*-*-*.com/




Thu, 04 Jan 2001 03:00:00 GMT  
 Passing a variable as the parameter for a query
Yes, in your code behind forms, do something like this
Dim qdf as QueryDef

'if you have created the query in code then
Set qdf = db.CreateQueryDef("", strSQL)
'     or
'if the query is stored, then
Set qdf=CurrentDb.QueryDefs("qryDoStuff")

qdf.Parameters![dtmBegReportPeriod] = Format(Me.txtBegReportDate,
"m/d/yyyy")
qdf.Parameters![dtmEndReportPeriod] = Format(Me.txtEndReportDate,
"m/d/yyyy")
qdf.Execute

And you can substitute a variable for Me.txtBegReportDate or even something
like Date().

Hope this helps,
Lilla

Quote:

>How do I pass a variable to be used as a parameter in a query?

>The only way I can get this to work is to first assign the variable to a
>control (e.g., a textbox).  And then pass the value of the control to the
>query.

>Is there a way to pass the variable to the query directly, avoiding the
>extra step of having to first assign it to a control and then referencing
>the control value as the parameter?

>Thanks for any ideas?
>Dave
>--------
>David R. Frick & Co., CPA
>http://www.frick-cpa.com





Thu, 04 Jan 2001 03:00:00 GMT  
 Passing a variable as the parameter for a query
Hi David,

The only way to refer to an Access Basic variable is by using Access Basic
code. therefore, you need to create a function that equals the value of that
variable, it could look like :

function GetValue()
  getvalue = variablename
end function

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

:How do I pass a variable to be used as a parameter in a query?
:
:The only way I can get this to work is to first assign the variable to a
:control (e.g., a textbox).  And then pass the value of the control to the
:query.
:
:Is there a way to pass the variable to the query directly, avoiding the
:extra step of having to first assign it to a control and then referencing
:the control value as the parameter?
:
:Thanks for any ideas?
:Dave
:--------
:David R. Frick & Co., CPA
:http://www.frick-cpa.com


:
:
:
:
:
:
:



Thu, 04 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing variables to query parameters

2. passing parameter to a parameter query

3. Passing Parameters to stored parameter queries using VB 5's Data Controls

4. Passing Parameters into a Pass-Through Query

5. Passing parameters to SQLServer using a Pass-Through query

6. calling parameter query from a parameter query

7. Global Variable passed to Parameter

8. Passing a Variable Parameter

9. Passing a variable type parameter to an .asp file

10. Passing variables/parameters between forms - newbie question

11. Passing variable value as parameter

12. Passing a variable from VB.NET to a Crystal report parameter or formula with no prompt

 

 
Powered by phpBB® Forum Software