when making a component (ocx file) of the combo box, and the wear components of the user control, then I compile it into ocx files. Once finished I include the components of it into the main program. then I do click and drag the combo box to the form, but that happens there is an error message "object variable or with block variable not set", what is causing it.
Meanwhile, when I compile the component made ​​no errors at all

please help to enlighten thank you for your help
warm regards

Dani AI

Generated

Short summary and focused fix checklist for this classic VB/ActiveX issue.

Runtime error 91 means code attempted to use an object reference that was not set; in controls that often appears while the control is being created (design-time) or when a property getter runs and expects a runtime-only object. (learn.microsoft.com)

Practical, high-value steps (quick order to try):

  • Make the IDE stop on the offending line so the exact procedure can be inspected. Set the VB/VBA Error Trapping option to break in class modules or break on all errors and reproduce the problem to see the failing line. That will show whether the error comes from initialization, a property Get/Let, or a property page. (msaccess.org)

  • Guard design-time initialization: avoid touching runtime services, other components, or unregistered objects while the control is being placed on a form. Check the container’s ambient UserMode before doing runtime-only work. Example pattern (inside the control):

    Private Sub UserControl_Initialize()
        If Not Ambient.UserMode Then Exit Sub   ' design-time: skip runtime init
        ' runtime-only initialization here
    End Sub

    Use the ambient UserMode property so design-time hosts and the runtime are handled differently. (learn.microsoft.com)

  • If the control fails to instantiate at all, check registration and dependencies: re-register the OCX with regsvr32 and use a dependency tool (Dependency Walker or similar) to find missing DLLs or wrong bitness (32-bit vs 64-bit) issues. Missing or unregistered dependencies will cause failures when the container tries to create the control. (learn.microsoft.com)

Additional items to verify: property Get/Let procedures that reference globals, the control’s InitProperties/PropertyChanged logic, project References in the host, and (when distributing) binary-compatibility/versioning so GUIDs and type info remain stable. The thread advice from , and points to these exact checks; ’s follow-up that a wrongly defined variable caused the error matches the most common root cause (uninitialized or incorrect object references).

Recommended Answers

All 5 Replies

It's been a while since I've done vb, but as I recall that is just a generic error indicating some class is not present that it needs to load. I've encountered it in the com and classic asp context in the past and usually I debug it by going into the system event log in windows and looking though the errors to see if some more useful context shows up (such as which class cannot be found). This is off the top of my head, but I want to say it would be in the application events log.

I'll let others chime in here with hopefully some more useful debugging info for you.

"iwannabesedated" thanks for your reply, I will try to re-check the component that I created

best regards

It's hard to be specific without seeing the code but generally the problem is because you declared a reference to an object but did not actually create an instance. It's the difference between

Dim myobj As SomeObject         'a reference to SomeObject

and

Dim myobj As New SomeObject     'an instance of SomeObject

ok heres the thing as i know it.
ill just relate to how ive come across the same error and hadndled it in excel vba.
when for instance i want to declares a range then put something in it, ill dimension it just as a range, but then i use variables like row and column number to set it. Without setting it i get the error..

After setting it, no error.
To set it, i use the statement like set xrange = activesheet.cells(x,y) where x and y are integers

i hopethis helps u eko. im looking into the same thing and if need be ill be still here.

@ Reverend jim @ fourty and thank you for your reply, after I double check my program turns out I have forgotten to define / wrong in defining variable in the class / component that I created

warm regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.