I would guess that your stored procedure is returning more than one recordset.
If this is the case, you can use the NextRecordset()
method to iterate through them.
MSDN:
- If a row-returning command executes successfully but returns no records, the returned Recordset object will be open but empty. Test for this case by verifying that the BOF and EOF properties are both True.
- If a non–row-returning command executes successfully, the returned Recordset object will be closed, which you can verify by testing the State property on the Recordset.
- When there are no more results, recordset will be set to Nothing.
This means I would suggest something like this to solve your problem:
Set rs = cmd.Execute
''# fetch the first value of the last recordset
Do Until rs Is Nothing
If rs.State = adStateOpen Then
If Not (rs.BOF And rs.EOF) Then
''# You can do a different sanity check here, or none at all
If rs.Fields(0).Type = adInteger Then
CustomerId = rs.Fields(0).Value
End If
End If
End If
Set rs = rs.NextRecordSet
Loop
MsgBox CustomerId
Tomalak
2009-05-11 06:29:21