473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Parameterised Queries in Access with ADO

I've built a query in Access and added a parameter to it called
[CurrentPeriod]. I'm trying to load the recordset by using an ADO
command and attaching a parameter to it but I keep getting an error
message when trying to open the recordset (arguments are out of
acceptable range or are in conflict with each other). I've checked the
data types and as much as I can think of - can anyone shed any light on
this? I'm sure I've done it before but can't find the code anywhere and
it's driving me crazy!!!

Thanks

Dave

--- Code ---

Dim o_conn As New ADODB.Connection
Dim rspols As New ADODB.Recordset
Dim m_conn_str As String
Dim i_period As Integer
Dim parmPeriod As New ADODB.Parameter
Dim cmdPBIRecs As New ADODB.Command

m_conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*****"
o_conn.CursorLocation = adUseClient
o_conn.ConnectionString = m_conn_str
o_conn.Open
i_period = CInt(InputBox("Which period are you reporting against?",
"Reports", ""))

cmdGetRecs.CommandText = "qrySalesReport"
cmdGetRecs.CommandType = adCmdStoredProc
cmdGetRecs.ActiveConnection = o_conn
cmdGetRecs.Parameters.Refresh

Set parmPeriod = cmdGetRecs.CreateParameter("CurrentPeriod",
adInteger, adParamInput, , i_period)
cmdGetRecs.Parameters.Append parmPeriod

rspols.Open cmdGetRecs.Execute, o_conn, adOpenForwardOnly,
adLockOptimistic

Nov 13 '05 #1
5 1548
Dim cmdPBIRecs As New ADODB.Command
cmdGetRecs.CommandText = "qrySalesReport"

Which Command object???

Darryl Kerkeslager
Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.

Demo: www.adcritic.com/interactive/view.php?id=5927

<u7***@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I've built a query in Access and added a parameter to it called
[CurrentPeriod]. I'm trying to load the recordset by using an ADO
command and attaching a parameter to it but I keep getting an error
message when trying to open the recordset (arguments are out of
acceptable range or are in conflict with each other). I've checked the
data types and as much as I can think of - can anyone shed any light on
this? I'm sure I've done it before but can't find the code anywhere and
it's driving me crazy!!!

Thanks

Dave

--- Code ---

Dim o_conn As New ADODB.Connection
Dim rspols As New ADODB.Recordset
Dim m_conn_str As String
Dim i_period As Integer
Dim parmPeriod As New ADODB.Parameter
Dim cmdPBIRecs As New ADODB.Command

m_conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*****"
o_conn.CursorLocation = adUseClient
o_conn.ConnectionString = m_conn_str
o_conn.Open
i_period = CInt(InputBox("Which period are you reporting against?",
"Reports", ""))

cmdGetRecs.CommandText = "qrySalesReport"
cmdGetRecs.CommandType = adCmdStoredProc
cmdGetRecs.ActiveConnection = o_conn
cmdGetRecs.Parameters.Refresh

Set parmPeriod = cmdGetRecs.CreateParameter("CurrentPeriod",
adInteger, adParamInput, , i_period)
cmdGetRecs.Parameters.Append parmPeriod

rspols.Open cmdGetRecs.Execute, o_conn, adOpenForwardOnly,
adLockOptimistic

Nov 13 '05 #2
Sorry - was messing round with the names - cmdPBIRecs and cmdGetRecs
are one in the same thing.

Nov 13 '05 #3
Sorry - was messing round with the names - cmdPBIRecs and cmdGetRecs
are one in the same thing.

Nov 13 '05 #4
Right, I've finally managed to dig up the piece of code I'd used
previously where I'd managed to pass a parameter in ADO to an Access
Query referencing the query as a stored procedure. The only thing I can
see that is different is that the output of the query wasn't directed
to a recordset (it's a make table). Can anyone explain why I can do one
way but not the other?

Cheers

Dave

Public Function GetPeriodRegistrations() As Integer

Dim o_conn As New ADODB.Connection
Dim cmdLoadRegs As New ADODB.Command
Dim parmPeriod As New ADODB.Parameter
Dim m_conn_str As String

m_conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
*****;"
o_conn.CursorLocation = adUseClient
o_conn.ConnectionString = m_conn_str
o_conn.Open

On Error Resume Next
o_conn.Execute ("DROP TABLE TMP_RegsPeriodReport;")
On Error GoTo Err_Proc
cmdLoadRegs.CommandText = "qryRegsPeriodReporting"
cmdLoadRegs.CommandType = adCmdStoredProc
cmdLoadRegs.ActiveConnection = o_conn
cmdLoadRegs.Parameters.Refresh
Set parmPeriod = cmdLoadRegs.CreateParameter("ReportingPeriod",
adInteger, adParamInput, , CInt(InputBox("Which period are you
currently reporting against?: ", "Reporting", "")))
GetPeriodRegistrations = parmPeriod
cmdLoadRegs.Parameters.Append parmPeriod
cmdLoadRegs.Execute
Set cmdLoadRegs = Nothing
o_conn.Close

Err_Proc:

If o_conn.State = adStateOpen Then
o_conn.Close
End If
Set o_conn = Nothing
Set cmdLoadRegs = Nothing
Set parmPeriod = Nothing

End Function

Nov 13 '05 #5
I believe this line:

rspols.Open cmdGetRecs.Execute, o_conn, [etc]

Should be:

rspols.Open cmdGetRecs, o_conn, [etc]
Darryl Kerkeslager
Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.

Demo: www.adcritic.com/interactive/view.php?id=5927
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
4
by: dschl | last post by:
Hi, I'm converting an Access 2000 database to Sql Server and must be missing something obvious. Using the Import utility in Sql Server, the Access queries seem to get executed and the...
2
by: John | last post by:
Hi New to sql server. using beta2 2005. What is the way to implement parameterised queries? I need the queries to be updatable as these would work as recordsets that vb.net forms will be bound...
5
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
3
by: shearichard | last post by:
Hi - I've got SQL that looks like this ... cursor = self.MySQLDb_conn.cursor(cursorclass=MySQLdb.cursors.DictCursor) sqlQuery = "SELECT * FROM T1 WHERE C1 = %s and C2 = %s" sql =...
2
by: B.r.K.o.N.j.A | last post by:
I'm using mysql 4.1 and php5.0.4. Since (AFAIK) this version of mysql supports parameterised queries, is there a way to accomplish that using mysql_... functions (looks like mysql client library is...
5
by: John | last post by:
Hi I have a parameterised query for a report like this; PARAMETERS Event_ID Short; SELECT DISTINCTROW Events., ... FROM Events WHERE (((Events.)=)); Now I am trying to run the report...
1
by: DebGuria | last post by:
I have written a managed C++ dll. I have to use that dll from C#, VB .NET and VB. It has got a parameterised propetyfor the very specific requirement. For example get_Pie(float f). When I am...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.