General discussion

Locked

Run time error 91 Object variable or ..

By hurdk ·
Hello,

I am having difficulty resolving the set instruction below.

I get runtime error 91 object variable or with block variable not set

I have tried many ways of handling this.


Public Sub LoadFindCbo()
Dim db As Database
Dim rs As Recordset
Dim sql As String
frmFind.cboCode.Clear
sql = "Select distinct code from PersonnelCommon order by code"

Set rs = dbEFC.OpenRecordset(sql) ' e r r o r

If rs.RecordCount > 0 Then
rs.MoveFirst
Do While rs.EOF = False
frmFind.cboCode.AddItem NoNull(rs!code)
rs.MoveNext
Loop
End If
rs.Close
End Sub


Thank you.

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Run time error 91 Object variable or ..

by smart_santanu In reply to Run time error 91 Object ...

Set rs = dbEFC.OpenRecordset(sql) ' e r r o r

where from do you get dbEFC? Probably it is a global variable. Check that you have properly initialised it like
set dbEFC = CreateObject(....)

Collapse -

Run time error 91 Object variable or ..

by hurdk In reply to Run time error 91 Object ...

Poster rated this answer

Collapse -

Run time error 91 Object variable or ..

by MadestroITSolutions In reply to Run time error 91 Object ...

This error is simply telling you that the object "dbEFC" has bot been set or instantiated.

OpenRecordSet works with either a Connection or a Database. In this case I can fairly say "dbEFC" must be a database (db), but you have to make sure it hasbeen properly instantiated, because the recordset will be set based on the information retrieved from it. For example this must be declared somewhere:

Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Dim dbEFC As Database
Set dbEFC = wrkJet.OpenDatabase("yourdb.mdb")

==============================================
A little piece of advice:
Why not use ADO instead?
just a thought

Good Luck!

Collapse -

Run time error 91 Object variable or ..

by MadestroITSolutions In reply to Run time error 91 Object ...

I missed a line of code (sorry):
This line should go before the first line on my code:
Dim wrkJet As Workspace
cya!

Collapse -

Run time error 91 Object variable or ..

by hurdk In reply to Run time error 91 Object ...

Poster rated this answer

Collapse -

Run time error 91 Object variable or ..

by dsa In reply to Run time error 91 Object ...

add this to your code.

set db = dbengine(0)(0)

Check you sql statement.

set rs = db.OpenRecordset(sql, dbOpenDynaset)
rs.MoveFirst
If rs.Bof and rs.Eof then
' Empty
Else
Add you loop statement here
Endif

Collapse -

Run time error 91 Object variable or ..

by hurdk In reply to Run time error 91 Object ...

Poster rated this answer

Collapse -

Run time error 91 Object variable or ..

by RRV In reply to Run time error 91 Object ...

Straight to answer.
This error occurs most of the time when you try to use any function expected to be in a dll and the dll is not instantiated or in memory. For example in your case the object dbEFC is not opened yet. This can be either your DAO connection is not done properly or incorrect version of DAO or simply the scope of your DB connection is void.

Use ADO connection to your database and check the status of connection before opening any recordset. Sample
set dbEFC=new ADODB.Connection
dbEFC.cursorlocation=aduseclient
dbEFC.connectionstring="dsn=yourdsn"
dbEFC.open

if dbEFC.State=adstateclosed then
msgbox "Connection to database failed !"
else
msgbox "Successfully connected."
set rsEFC=new ADODB.Recordset
rsEFC.open "Select your data",dbEFC,adopenforwardonly,adlockreadonly
if rsEFC.state=adstateclosed then
msgbox "No Data selected
else
do while not rsEFC.EOF
'Do your data processing
rsEFC.movenext
loop
endif
endif

of course you should have a reference to Microsoft ActiveX Data objects [some version above 2.0]

RV

Collapse -

Run time error 91 Object variable or ..

by hurdk In reply to Run time error 91 Object ...

Poster rated this answer

Collapse -

Run time error 91 Object variable or ..

by hurdk In reply to Run time error 91 Object ...

This question was closed by the author

Back to Web Development Forum
10 total posts (Page 1 of 1)  

Related Discussions

Software Forums