Parameter query won't work with an Array of Values
- From: Piper <Piper@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 13 Aug 2007 08:52:00 -0700
Hi - I'm using VB in an Access DB. I'm trying to open an ADOB.Recordset using
a Command Object by passing a Variant array. for some reason it works fine
when I pass only one value, but now when I'm trying to pass an array I get
this error:
Run-time error '3001';
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.
The parameter query takes 2 values of type Long. The only values I can pass
are of type Variant, I don't think this is the problem because when I use the
same query with only 1 parameter it works.
Here is my recordset Sub for 1 parameter:
Sub setRcdSetCmd(rcdSet As ADODB.Recordset, qry As String, par As Variant)
setCmd Cmd, qry
rcdSet.CursorType = adOpenStatic
rcdSet.LockType = adLockOptimistic
Set rcdSet = Cmd.Execute(Parameters:=par)
End Sub
Here is the recordset sub that I was trying to use for the array:
Sub setRcdSetCmdAry(rcdSet As ADODB.Recordset, qry As String,
ParamArray par() As Variant)
setCmd Cmd, qry
rcdSet.CursorType = adOpenStatic
rcdSet.LockType = adLockOptimistic
Set rcdSet = Cmd.Execute(Parameters:=par()) **********
End Sub
Here is my Command function;
Function setCmd(Cmd As ADODB.Command, qry As String) As ADODB.Command
With Cmd
.CommandText = qry
.CommandType = adCmdStoredProc
Set .ActiveConnection = setCnxn
End With
End Function
The line with the *'s is the one that throws the error
I've tried calling the setRcdSetCmdAry 2 ways:
setRcdSetCmdAry rcdSet, qry, 13, 1
and
dim param(2) as variant
param(0) = 13
param(1) = 1
setRcdSetCmdAry rcdSet, qry, param()
I've also tried using the setRcdSetCmdAry sub withouht the ParamArray. I'm
not sure what exactly it is that I'm doing wrong, when I run the query in
Access it works.
I also have one other question just if anyone happens to know....
One of my primary keys is of type long, I've been doing a lot of programming
all using type long and example data. But I've ran into a snag - half of the
values are regular numbers like 127985 and the other half have 0's in the
front like 027854. When I try to use the numbers with the 0's in front Access
trunks the 0 and gives me 27854 insted of 027854. Is there anything I can do
to preserve the 0 in front (and all of my hard work programming with type
long)?
Any help is appreciated
--
Piper
.
- Prev by Date: Re: How do I link the results from sp_executeSQL to a gridview?
- Next by Date: Re: How does sql ExecuteReader() work?
- Previous by thread: Re: How do I link the results from sp_executeSQL to a gridview?
- Next by thread: Re: How does sql ExecuteReader() work?
- Index(es):
Relevant Pages
|
|