MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 490
- Office Version
- 365
- Platform
- Windows
OK, so after lots of searching for ADO recordset returns -1, I've tried all the suggestions, but each time I get to the line of code following the opening of the recordset, the cursortype option is not set to the requested value. My example uses an ADO command object to execute the stored procedure, but the logic works with the exception of being able to find the record count of the loaded data.
Here's the relevant code:
But when I'm at the line following the Open, the Locals window shows different settings for the recordset object, i.e. cursor type is adOpenForwardOnly, even though it's set to adOpenKeyset:
I've tried removing the command object and setting the first argument of the open recordset to be the "EXECUTE [dbo].[usp..." but get the same issue.
Anyone able to tell me what I'm missing or doing wrong?
Thanks in advance
Martin
Here's the relevant code:
VBA Code:
Dim objConn As ADODB.Connection
Dim objCmd As ADODB.Command
Dim objRS As ADODB.Recordset
Dim lngRecordCount As Long
'Creates the connection object
Set objConn = OpenConn
'Create command object
Set objCmd = New ADODB.Command
Set objCmd.ActiveConnection = objConn
'Create the command to get the data and execute
objCmd.CommandText = "EXECUTE [dbo].[usp_GetBulkConstruction]"
objCmd.CommandType = adCmdText
objCmd.Execute
'Create and open recordset object
Set objRS = New ADODB.Recordset
objRS.Open objCmd, , adOpenKeyset, adLockReadOnly
I've tried removing the command object and setting the first argument of the open recordset to be the "EXECUTE [dbo].[usp..." but get the same issue.
Anyone able to tell me what I'm missing or doing wrong?
Thanks in advance
Martin