• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Error 91 Object variable or With block not set

Error 91 Object variable or With block not set.

This is the error I get from the initial form in the "form load" event.

How do I resolve this error? It doesn't appear to be my code. Is there a problem with the compiler? Do I need a new run time? Could the system need new dll's?

Any assistance greatly appreciated.

Melvin
0
Melvin
Asked:
Melvin
1 Solution
 
twardCommented:
Showing the code from the Form_Load event will help.
0
 
MirkwoodCommented:
Does it happen only at run-time? Otherwise you can see the line that failed.
The reason is that one of your objects is nothing
0
 
kfrickCommented:
I have found that the Form_Load event is not the place to initialize features of your form, because thay do not yet exist! The form has not yet created the control you are trying to modify with your code.

I have used two methods. The first is th Form_Activate event:

Sub Form_Activate()
Static bInit as boolean
  If Not bInit then
    ' put your initialization code here
    bInit = True
  End If
End Sub

The bInit boolean prevents your code from running more than once. It will run the first time the form is opened.

The other soliution is to put a timer on your form, and use the Timer event to initialize your form:

Put a timer on your form. Call it tmrStartUp. Set it's Enabled property to True. Set it's Interval property to 100. Paste this code to the form:

Sub tmrStartUp_Timer()
  tmrStartUp.Enabled = False
  ' putyour initialization code here
End Sub

Play around with these two schemes to find which one you like best!

Good Luck!

-kf
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
MelvinAuthor Commented:
I have additional information.  The object is a database created using Visual Basic.  I have upgraded Visual Basic with Service Pack 2.  Now I can't open the database.  The more descriptive error message is: 3041 --  Can't open a database created with a previous version of your application.

I suppose I will have to reinstall the original VB and not include Service Pack 2.  This may resolve the problem.
0
 
dgb001Commented:
I wondered if it might be database related, I'm sure the comments above are more helpful than this, but I got the same error 91 recently, which was the result of trying to close a database table before it was opened.


0
 
MelvinAuthor Commented:
I resolved the problem by upgrading the database. The problem was that I built the database using VB. When I installed Service Pack 2 in VB, my application could no longer open the database created with the older version of VB. Using Microsoft Access I converted the database to Access 7.0 and now everything works fine.

I appreciate kfrick's response, but my failure to adequately explain the issue initially, resulted in an answer that didn't resolve my problem. My fault.
0
 
kfrickCommented:
No problem! Glad you found the answer! Happy Holidays!
-kf
0
 
linda101698Commented:
I am posting the solution found by Melvin so it can be saved in the previously asked questions.  Please see your customer service question for an explanation.

Linda Gardner
Customer Service @ Experts Exchange


Comment
     From: Melvin
                                  Date: Monday, December 21 1998 - 06:01AM PST

     I resolved the problem by upgrading the database. The problem was that I
     built the database using VB. When I installed Service Pack 2 in VB, my
     application could no longer open the database created with the older version
     of VB. Using Microsoft Access I converted the database to Access 7.0 and
     now everything works fine.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now