
January 13th, 2006, 04:03 PM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 1
Time spent in forums: 1 h 25 m 32 sec
Reputation Power: 0
|
|
|
RESOLVED: Error 91 "object variable or with block variable not set" in VB6
I'm getting Runtime Error 91, "Object variable or With Block variable not set" on the following code:
Code:
Dim strSQL As String, strFundCode As String
Dim rstMove As ADODB.Recordset
Dim flgCostsAlreadyPresent As Boolean
'Check if there are already costs in destination year
'If this recordset is not empty then there are costs in destination year
With rstMove
strSQL = "SELECT count(KeyNo) as cnt FROM tblITIPFunding " _
& "WHERE KeyNo='" & ctlITIPRecord(Index).KeyNo & "' AND ProgramNo='" & strFund & "' AND Year>='" & Year & "';"
.Open strSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText ''<----------error occurs on this line.
.MoveFirst
flgCostsAlreadyPresent = (!cnt > 0)
.Close
End With
I'm writing this with VB 6. The intent of this block of code is to check whether records exist in our database which meet given criteria. The value stored in strSQL at the time the error occurs works correctly if executed in the database (MSAccess 2000).
In the line with the error, "cnn" refers to a global adodb.connection object, which is open and works fine elsewhere in the code. Can anyone give me some insight into what might be causing this problem?
Thanks,
Eldin
edit - The problem was resolved by changing the line:
Dim rstMove As ADODB.Recordset
to this:
Dim rstMove As New ADODB.Recordset
Last edited by eldin : January 13th, 2006 at 05:13 PM.
Reason: RESOLVED
|