Run time error 91

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.
laurapAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
VBSysCOM1Connect With a Mentor Commented:
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
 
AndrewDevCommented:
This article explains the problem and its workaround

http://support.microsoft.com/support/kb/articles/Q113/3/97.asp
0
 
laurapAuthor Commented:
Forgot to mention......the program is written in VB.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
laurapAuthor Commented:
that article refers to Microsoft Project.......i'm not sure how that applies to my problem.
0
 
deightonCommented:
Form_Load event.

Private Sub Form_Load()

dbs.refresh

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

data1.refresh




0
 
mmcmillenCommented:
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
 
laurapAuthor Commented:
can't do dbs.refresh refresh not a method of the database object (get method or data member not found)
0
 
thenrichCommented:
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
 
deightonCommented:
Where does the datacontrol come in to it if dbs is a database object?
0
 
VKCommented:
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
 
laurapAuthor Commented:
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
 
laurapAuthor Commented:
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
 
laurapAuthor Commented:
i'm wondering if these people may need to set their reference to the dao object library in their database?
0
 
thenrichCommented:
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
 
VKCommented:
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
 
laurapAuthor Commented:
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
 
VKCommented:
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
 
laurapAuthor Commented:
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
 
laurapAuthor Commented:
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
 
VKCommented:
for the MDAC Version search the registry after "MDACVer"
0
 
laurapAuthor Commented:
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
 
issamtaherCommented:
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
 
MattiCommented:
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
 
laurapAuthor Commented:


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
 
VBSysCOM1Commented:
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
 
laurapAuthor Commented:
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
 
VBSysCOM1Commented:
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
 
laurapAuthor Commented:
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
 
MattiCommented:
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
 
laurapAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.