Solved

Run time error 91

Posted on 2001-06-11
30
380 Views
Last Modified: 2012-05-04
I wrote a program that is now being installed on over 100 machines off site.  it works fine on most machines but a few people have encountered "Run-Timer Error 91: Object Variable or With block variable not set." upon opening a form that contains a dbgrid control.

This program uses DAO and has a MS Access database as the back-end.

the dbgrid control has a datacontrol as its datasource. The datacontrols recordsource is set in the Form_Load event.

Private Sub Form_Load()
data1.refresh
set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")

....

Exit Sub

(note: i added the data1.refresh line before referencing the the recordset per sugguestion in a MS Knowledge base article but the person is still getting teh Run-Time 91 Error)

After receiveing the error, the form opens with no data in the dbgrid.

In previous instances of this problem, the user simply needed to install a newer version of MDAC. However, even after intalling the correct version of MDAC a few people still get this error and the form opens with no data in the dbgrid control.
0
Comment
Question by:laurap
  • 14
  • 4
  • 3
  • +6
30 Comments
 
LVL 5

Expert Comment

by:AndrewDev
Comment Utility
This article explains the problem and its workaround

http://support.microsoft.com/support/kb/articles/Q113/3/97.asp
0
 

Author Comment

by:laurap
Comment Utility
Forgot to mention......the program is written in VB.
0
 

Author Comment

by:laurap
Comment Utility
that article refers to Microsoft Project.......i'm not sure how that applies to my problem.
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Form_Load event.

Private Sub Form_Load()

dbs.refresh

set data1.recordset=dbs.openrecordset("select ....

data1.refresh




0
 
LVL 2

Expert Comment

by:mmcmillen
Comment Utility
Is the database in a directory or drive that they don't have? Check the connect and databasename properties on the dsr. MAke sure they are pointing at the same directory and db that you are.
0
 

Author Comment

by:laurap
Comment Utility
can't do dbs.refresh refresh not a method of the database object (get method or data member not found)
0
 
LVL 5

Expert Comment

by:thenrich
Comment Utility
My guess is that your application is still referencing the old MDAC. If it was me i might try to incorporate the MDAC into my setup routine. Although quite large it will insure that your users will aquire the correct MDAC all the time.
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Where does the datacontrol come in to it if dbs is a database object?
0
 
LVL 6

Expert Comment

by:VK
Comment Utility
if you are sure that you get the error 91 at line

set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")

dbs couldn't be initialized.
Check was happens before. Can you reproduce the error in debug mode ?
0
 

Author Comment

by:laurap
Comment Utility
deighton,

set data1.recordset=dbs.openrecordset("select [chaptercode], chapter from chapters order by chapter;")

******************

the datacontrol is the datasource for the dbgrid control on the form.  it's recordsource is set at run-time in the form_load event.

(dbs is set at the start of the program using app.path since i don't know where the database will be installed on each user's machine.)

i'm assuming the error is running at the set data1.recordset line since after error, the form does open but the dbgrid does not display any information........
0
 

Author Comment

by:laurap
Comment Utility
vk,
unfortunately,
so far i've not been able to recreate the error ....I never got the error on any of the machines (at least 20 of them)  on which i tested the program before sending it out. i'm working over the phone with two different people that are getting this error.

btw, some people did get this error during beta testing...it was solved (or so i thought) but updating to DAO 3.6 object library.........
0
 

Author Comment

by:laurap
Comment Utility
i'm wondering if these people may need to set their reference to the dao object library in their database?
0
 
LVL 5

Expert Comment

by:thenrich
Comment Utility
setting it in their database shouldn't make any difference. The end user doesn't even need Access on their machine. I'm thinking for some reason that the DAO 3.6 setup failed.
0
 
LVL 6

Expert Comment

by:VK
Comment Utility
if i have such a problem i would do following:


MsgBox "dbs= " & dbs is nothing

set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")

and at other places where you think it's good to obsereve some variables.

then make an exe. Copy it on a machine where the error happens. ... and so on

Or you use a tool like dll-show to observe what dll's are loaded.


0
 

Author Comment

by:laurap
Comment Utility
thenrich,
the mdac 2.5 setup, while not incorporating into the setup program, was included on the cd that i sent out to people.(i downloaded it from the microsoft site).  both individuals having this program said that they ran the mdac 2.5 setup and that they were informed it was successfully installed.  is there a way to confirm if it was, infact successfully installed on their machines?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:VK
Comment Utility
Do you have both references to DAO 3.6 and ADO ?
Then you should always declare variables like:

dim db1 as dao.database
dim db2 as adodb.database

if you don't so vb takes the entry in your references that is listed before.
0
 

Author Comment

by:laurap
Comment Utility
vk,
as of yet i haven't come across a machine where i can reproduce the problem (it works fine on around 20 or so machines that i tried it on).

will look into the dll utility.
0
 

Author Comment

by:laurap
Comment Utility
vk,
just dao references, no ado.

however i will adjust the declaration as you suggested and forward the users an updated exe and see if that solves the problem.
0
 
LVL 6

Expert Comment

by:VK
Comment Utility
for the MDAC Version search the registry after "MDACVer"
0
 

Author Comment

by:laurap
Comment Utility
i adjusted the declarations and emailed the executable to the people that are having the problem.  unfortunately they are still getting the run-time 91 error. they've also checked the registry and verified that they have mdac 2.50......
0
 
LVL 1

Expert Comment

by:issamtaher
Comment Utility
dear laurap
in past i have this error and i fixed it by this:

let say the intryform has this error.
and then error appear when i say "intryform.show"

all what i do just :
1- unload intryform
2-intryform.show

isn't it

as i knew you.

pleas try it and tell me.
good bya.
0
 

Accepted Solution

by:
VBSysCOM1 earned 200 total points
Comment Utility
Note I have ran in to this problem myself and found that a the work around is in stead of useing the onload event use the Form_Initialize event. This will work with know error.
See the problem is the Load event is faster than the database connection so on load the form loads and calls on your code. Initialize event is the propper way to fire events when dealing with a database.

Private Sub Form_Load()
data1.refresh
set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")
....
Exit Sub

Private Sub Form_Initialize()
data1.refresh
set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")
End Sub
0
 
LVL 14

Expert Comment

by:Matti
Comment Utility
Hi!


The problem is that your program uses the datasource or some referenced objects before the database or recordset object is open.

Try Form_Initialize event or sub main as start for this program.

Matti
0
 

Author Comment

by:laurap
Comment Utility


i've establisehd that the problem is with the versioning of dao36o.dll.

on one machine there was three version of the file. one in the app folder, one in the microsoft shared/dao folder and and older one in the system32 folder.  after asking this user to rename the dll in the system32 folder, the app found the correct one and then worked.

success is fleeting.  Two other users only have the dao360.dllin the app folder (which was installed by my program).  i had them copy it to the system32 folder but error 91 still generates.  i had them delete it from there and copy it to the microsoft shared/dao folder and, again, the problems still remains.  

any suggestions?

p.s. matti, the database object is set in the form_load even of a splash screen that pops up at the start of the program..........

0
 

Expert Comment

by:VBSysCOM1
Comment Utility
laurp,
      As I stated in the above you need to fire the event in the Form_Initialize Event not in form load. Do this and it will work for you. dao36o.dll this is not the problem. The problem is where you call the event.

Private Sub Form_Initialize()
data1.refresh
set data1.recordset=dbs.openrecordset("select [chaptercode], chapter order by chapter;")
End Sub





Thank You and have a good day.
         
0
 

Author Comment

by:laurap
Comment Utility
VBSysCom1,
I will try your suggestion and forward an updated exe to the users having this proble.   But As i mentioned, this problem did not occur on the 20 or so machines that it was tested on before being distributed.  It was then distributed to 120 people off-site.  so far 4 people have reported this problem.  it has been rectified on one machine by getting rid of an older version of dao360.dll, so clearly this DOES factor into the issue.

as i said i will move the code the the Form_initilize event since, per your comment, this is the correct place for it.  will let you know if that solves the problem.
0
 

Expert Comment

by:VBSysCOM1
Comment Utility
Like I was saying I had this problem about 6 months ago and as soon as I fired the event in the Form_Initialize. Problem was solved I was using the AddNew In The Form Load Event And Was Getting The Same RunTime Error 91 As You Are Now when Refreshing The DataBase. So When I Move The Code To The Form_Initialize()It Work Like A Champ. DAO is strange when it used but if coded properly It Works well.

Private Sub Form_Initialize()
data1.RecordSet.MoveLast
data1.AddNew
End Sub

I also have an OCX file that I created the will handle any DAO error and write it to a Error.txt file. Which makes it very easy for the programming to debug a program. Because as all IT people know, to ask the user is like pulling teeth(lol). Let me know if you are interested in this.

Thank you and have a good day!
0
 

Author Comment

by:laurap
Comment Utility
thanks...i am going to try this...but, like i said i have to forward it to people off site and get their response.  hopefully this will do the trick.  i'm ready to move on the next problem that i'm sure will rear it's head shortly.


thanks and will get back with the results....

that ocx sounds interesting.  yes i would like more info..
0
 
LVL 14

Expert Comment

by:Matti
Comment Utility
Hi!

When I look more closer the other comments in this thread i found that you already had here very similar method proposed from VBSysCom1. If the problem is this then do accept earlier proposals in first case.

Some of those users might use the mouse buttons at moment when program load's, dependence where the focus is att this time, this might cause such event which uses database before the connection is ready.

Matti



0
 

Author Comment

by:laurap
Comment Utility
using the form_initiallize event worked and error 91 no longer appears (sorry i doubted you).  

i now receive error 429....if i can't rectify it...i'll be back.

Thanks everyone.........
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now