Passing two parameters tp a query in VBA 
Author Message
 Passing two parameters tp a query in VBA

Hello,

I've build a query in VBA, and I need to pass two parameters. How can I do
that?

Thanks
Ulrik
--
--------------------------------
"I'm not a vegetarian because I love animals. I'm a vegetarian because I
hate plants."
A. Whitney Brown



Sun, 01 Feb 2004 16:55:20 GMT  
 Passing two parameters tp a query in VBA
If you construct the SQL String "in-line" (meaning in VBA code), then you
can just get the 2 Values you wanted and use them to construct your SQL
String.  For example: If I want to select Records that have Numeric Field1
equal to the Value in TextBox1 on the Form AND Text Field2 equal to the
Value in TextBox2 then my SQL construction is:

strSQL = "SELECT ... WHERE [Field1] = " & Me.TextBox1.Value & _
                " AND [Field2] = '& Me.TextBox2.Value & "';"

Note that Text Values must be delimited by SingleQuotes like above.
DateTime Values must be in American format ("mm/dd/yyyy") and delimited by
hash (#) symbols.

Use normal logical operators (AND, OR, XOR, EQV, IMP) to connect the 2
criteria as per your requirements.

If you use a saved Query, you can use the Parameters collection of the
QueryDef object to assign Values to the Parameters prior to using the
QueryDef.  Check out the Topic "PARAMETERS Declaration" (especially the DAO
Example) in the Microsoft Jet SQL Reference of the Access Help.

HTH
Van T. Dinh


Quote:
> Hello,

> I've build a query in VBA, and I need to pass two parameters. How can I do
> that?

> Thanks
> Ulrik
> --
> --------------------------------
> "I'm not a vegetarian because I love animals. I'm a vegetarian because I
> hate plants."
> A. Whitney Brown



Sun, 01 Feb 2004 20:43:18 GMT  
 Passing two parameters tp a query in VBA
Hello,

Thanks for the help. This is the code:

PARAMETERS Forms!frmSendEmail!txtCustomer Text;
SELECT tblOrder.CustomerID, tblOrder.Customer, tblOrder.ItemID,
tblOrder.ItemName, tblOrder.Price
FROM tblItem
HAVING (((tblOrder.Customer)=[Forms]![frmSendEmail]![txtCustomer]))
ORDER BY tblOrder.CustomerID, tblOrder.ItemID

and this is how I got round it (thanks Bas Cost Budde):
qd.parameters(0) = value1
qd.parameters(1) = value2

dunno if it's a good way, but it works :-)
Thanks
Ulrik


Quote:
> If you construct the SQL String "in-line" (meaning in VBA code), then you
> can just get the 2 Values you wanted and use them to construct your SQL
> String.  For example: If I want to select Records that have Numeric Field1
> equal to the Value in TextBox1 on the Form AND Text Field2 equal to the
> Value in TextBox2 then my SQL construction is:

> strSQL = "SELECT ... WHERE [Field1] = " & Me.TextBox1.Value & _
>                 " AND [Field2] = '& Me.TextBox2.Value & "';"

> Note that Text Values must be delimited by SingleQuotes like above.
> DateTime Values must be in American format ("mm/dd/yyyy") and delimited by
> hash (#) symbols.

> Use normal logical operators (AND, OR, XOR, EQV, IMP) to connect the 2
> criteria as per your requirements.

> If you use a saved Query, you can use the Parameters collection of the
> QueryDef object to assign Values to the Parameters prior to using the
> QueryDef.  Check out the Topic "PARAMETERS Declaration" (especially the
DAO
> Example) in the Microsoft Jet SQL Reference of the Access Help.

> HTH
> Van T. Dinh



> > Hello,

> > I've build a query in VBA, and I need to pass two parameters. How can I
do
> > that?

> > Thanks
> > Ulrik
> > --
> > --------------------------------
> > "I'm not a vegetarian because I love animals. I'm a vegetarian because I
> > hate plants."
> > A. Whitney Brown



Sun, 01 Feb 2004 21:08:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing a parameter to two queries

2. Can't Pass Query name Tp Report Using Docmd

3. Passing Query Parameter In VBA

4. Passing parameters from VBA to a Query

5. Passing parameters to Access Query from VBA

6. passing parameter to a parameter query

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

8. Passing Parameters into a Pass-Through Query

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

10. Using Parameters from VBA Code in a Parameter Query Export

11. parameter query in VBA when parameter not a field

12. Passing two parameters ???

 

 
Powered by phpBB® Forum Software