-
Aug 13th, 2010, 05:32 AM
#1
Thread Starter
Addicted Member
[RESOLVED] recordset.open gives runtime error 3001 "Arguments are of the wrong type.."
I don't understand why I would get the following error when I try to open a recordset and pass a connection-object.
runtime error 3001 "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
Code:
Private Function fnOpenRecordset(ByVal cn As ADODB.Connection, _
ByVal Source As String, _
Optional ByVal CursorType As ADODB.CursorTypeEnum = ADODB.CursorTypeEnum.adOpenForwardOnly, _
Optional ByVal LockType As ADODB.LockTypeEnum = ADODB.LockTypeEnum.adLockReadOnly, _
Optional ByVal Options As Long = ADODB.CommandTypeEnum.adCmdText, _
Optional ByVal lCacheSize As Long = 1, _
Optional ByVal CursorLocation As ADODB.CursorLocationEnum = 0) As ADODB.Recordset
Set fnOpenRecordset = New ADODB.Recordset
If CursorLocation <> 0 Then fnOpenRecordset.CursorLocation = CursorLocation
fnOpenRecordset.CacheSize = lCacheSize
Call fnOpenRecordset.Open(Source:=Source, _
ActiveConnection:=cn, _
CursorType:=CursorType, _
LockType:=LockType, _
Options:=Options)
End Function
Public Sub MergeClients(ByVal cn As ADODB.Connection)
Dim rs As ADODB.Recordset
Set rs = fnOpenRecordset(cn, "SELECT ClientID FROM Clients")
'Do something with the recordset
End Sub
I'm using Office 2000, I have a reference to the Microsoft ActiveX Data Objects 2.8 Libray.
The problem arrises when I pass an Connection object (which is also an ADODB.Connection from 2.8) from my VB6 program to the document using the MergeClient method.
But when I create a connection in de document itself it doesn't give the error, and it just works:
Code:
Public Sub MergeClients(ByVal sConnectionString As String)
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Call cn.Open(ConnectionString:=sConnectionString)
Set rs = fnOpenRecordset(cn, "SELECT ClientID FROM Clients")
'Do something with the recordset
End Sub
-
Aug 13th, 2010, 08:26 AM
#2
Re: recordset.open gives runtime error 3001 "Arguments are of the wrong type.."
I don't know what's wrong, but it looks like the function fnOpenRecordset attempts recursion, which would create an out of stack space error eventually. I think some code is missing or something:
- Enter the function
- Create a new recordset
- Check the cursor
- set the cachesize
- goto step 1
That doesn't make sense.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 13th, 2010, 09:05 AM
#3
Re: recordset.open gives runtime error 3001 "Arguments are of the wrong type.."
An ADO Recordset must be created within the same Process that instantiated the ADO Connection object.
Your VB6 app is one Process while the Office app is another.
http://support.microsoft.com/kb/248287
-
Aug 16th, 2010, 02:52 AM
#4
Thread Starter
Addicted Member
Re: recordset.open gives runtime error 3001 "Arguments are of the wrong type.."
Originally Posted by brucevde
An ADO Recordset must be created within the same Process that instantiated the ADO Connection object.
Your VB6 app is one Process while the Office app is another.
http://support.microsoft.com/kb/248287
Thanx, that makes it clear.. I already tought it would be something like that.. Not that I like it ofcourse... grrr....
Just tried it just for testing purposes, and when I replace the fnOpenRecordset with the following implementation (as suggested in the microsoft article) it does work..
Code:
Private Function fnOpenRecordset(ByVal cn As ADODB.Connection, _
ByVal Source As String, _
Optional ByVal Options As Long = ADODB.CommandTypeEnum.adCmdText) As ADODB.Recordset
Set fnOpenRecordset = cn.Execute(Source, Options:=Options)
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|