A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

ADO Parameter Query



 
 
Thread Tools Display Modes
  #1  
Old May 28th, 2004, 09:33 PM
Tony_VBACoder
external usenet poster
 
Posts: n/a
Default ADO Parameter Query

I have a bunch of Parameter Queries that I have been
calling with VBA. But now I am converting my code to use
ADO recordsets. How would I change my old code to ADO
(see below)?

Private Sub GetParameterQuery()
Dim dbs As Database, rst As Recordset, qdf As QueryDef
' Set database variable to current database.
Set dbs = CurrentDb
' Set the QueryDef object
Set qdf = dbs.QueryDefs("qryMyParameterQuery")
' Set the parameters of the query
qdf.Parameters("[Start Year]") = 2000
qdf.Parameters("[End Year]") = 2004
' Open Recordset object
Set rst = qdf.OpenRecordset()



  #2  
Old May 29th, 2004, 12:28 PM
Gerald Stanley
external usenet poster
 
Posts: n/a
Default ADO Parameter Query

Try something along the lines of

Private Sub GetParameterQuery()
Dim comm As ADODB.Command
Dim pm As ADODB.Parameter
Dim rst As ADODB.recordset

Set comm = New ADODB.Command
Set comm.ActiveConnection = CurrentProject.Connection
comm.CommandText = "qryMyParameterQuery"
comm.CommandType = adCmdStoredProc
Set pm = comm.CreateParameter("Start Year", adNumeric , ,
, 2000)
comm.Parameters.Append pm
Set pm = comm.CreateParameter("End Year", adNumeric , , , 2004)
comm.Parameters.Append pm

Set rst = comm.Execute

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I have a bunch of Parameter Queries that I have been
calling with VBA. But now I am converting my code to use
ADO recordsets. How would I change my old code to ADO
(see below)?

Private Sub GetParameterQuery()
Dim dbs As Database, rst As Recordset, qdf As QueryDef
' Set database variable to current database.
Set dbs = CurrentDb
' Set the QueryDef object
Set qdf = dbs.QueryDefs("qryMyParameterQuery")
' Set the parameters of the query
qdf.Parameters("[Start Year]") = 2000
qdf.Parameters("[End Year]") = 2004
' Open Recordset object
Set rst = qdf.OpenRecordset()



.

  #3  
Old June 1st, 2004, 01:50 PM
Tony_VBACoder
external usenet poster
 
Posts: n/a
Default ADO Parameter Query

Gerald,

Worked perfect. Thank you.


-----Original Message-----
Try something along the lines of

Private Sub GetParameterQuery()
Dim comm As ADODB.Command
Dim pm As ADODB.Parameter
Dim rst As ADODB.recordset

Set comm = New ADODB.Command
Set comm.ActiveConnection = CurrentProject.Connection
comm.CommandText = "qryMyParameterQuery"
comm.CommandType = adCmdStoredProc
Set pm = comm.CreateParameter("Start Year", adNumeric , ,
, 2000)
comm.Parameters.Append pm
Set pm = comm.CreateParameter("End Year", adNumeric , , ,

2004)
comm.Parameters.Append pm

Set rst = comm.Execute

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I have a bunch of Parameter Queries that I have been
calling with VBA. But now I am converting my code to

use
ADO recordsets. How would I change my old code to ADO
(see below)?

Private Sub GetParameterQuery()
Dim dbs As Database, rst As Recordset, qdf As QueryDef
' Set database variable to current database.
Set dbs = CurrentDb
' Set the QueryDef object
Set qdf = dbs.QueryDefs("qryMyParameterQuery")
' Set the parameters of the query
qdf.Parameters("[Start Year]") = 2000
qdf.Parameters("[End Year]") = 2004
' Open Recordset object
Set rst = qdf.OpenRecordset()



.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.