Results 1 to 4 of 4

Thread: [RESOLVED] recordset.open gives runtime error 3001 "Arguments are of the wrong type.."

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2009
    Posts
    197

    Resolved [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

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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:
    1. Enter the function
    2. Create a new recordset
    3. Check the cursor
    4. set the cachesize
    5. 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

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2009
    Posts
    197

    Re: recordset.open gives runtime error 3001 "Arguments are of the wrong type.."

    Quote Originally Posted by brucevde View Post
    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
  •  



Click Here to Expand Forum to Full Width