Link to home
Start Free TrialLog in
Avatar of laurap
laurap

asked on

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.
Avatar of AndrewDev
AndrewDev

This article explains the problem and its workaround

http://support.microsoft.com/support/kb/articles/Q113/3/97.asp
Avatar of laurap

ASKER

Forgot to mention......the program is written in VB.
Avatar of laurap

ASKER

that article refers to Microsoft Project.......i'm not sure how that applies to my problem.
Form_Load event.

Private Sub Form_Load()

dbs.refresh

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

data1.refresh




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.
Avatar of laurap

ASKER

can't do dbs.refresh refresh not a method of the database object (get method or data member not found)
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.
Where does the datacontrol come in to it if dbs is a database object?
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 ?
Avatar of laurap

ASKER

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........
Avatar of laurap

ASKER

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.........
Avatar of laurap

ASKER

i'm wondering if these people may need to set their reference to the dao object library in their database?
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.
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.


Avatar of laurap

ASKER

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?
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.
Avatar of laurap

ASKER

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.
Avatar of laurap

ASKER

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.
for the MDAC Version search the registry after "MDACVer"
Avatar of laurap

ASKER

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......
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.
ASKER CERTIFIED SOLUTION
Avatar of VBSysCOM1
VBSysCOM1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of laurap

ASKER



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..........

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.
         
Avatar of laurap

ASKER

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.
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!
Avatar of laurap

ASKER

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..
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



Avatar of laurap

ASKER

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.........