I wasn't sure if this should go under SQL Server or Access since it is a hybrid or both.
I'm having a problem using the ADODB.Command and Recordset objects in Access to connect to SQL Server commands. I'm used to writing code to conenct to SQL in VBA (in Access) a certain way, and I recently changed to a new place where they use a different SQL Server among other things.
Anyways, the way I used to write code using the ADODB.Command and ADODB.Recordset isn't working...
I have a stored procedure that has 1 parameter and I'm calling it this way:
Expand|Select|Wrap|Line Numbers
- Set cmdNetwork = New ADODB.Command
- With cmdNetwork
- .CommandType = adCmdStoredProc
- .CommandText = "sp_DIS_ListNetworks"
- .Parameters.Append .CreateParameter("@NetworkID", adInteger, adParamInput)
- .Parameters("@NetworkID").Value = CInt(lstNetworks.Value)
- .ActiveConnection = CurrentProject.Connection
- End With
- 'setup recordset
- Set rsNetwork = New ADODB.Recordset
- rsNetwork.Open cmdNetwork.Execute, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
Also, when it I go to open the recordset (rsNetwork.Open) I get an error (Arguments of the wrong type, are out of acceptable range, or are in conflict with one another.) no matter what I set the cursor and lock method to. I don't get an error when I leave off all arguments after .Execute.
Would anyone be able to refresh me on why these errors are happening?
Thank you!
Zach