“Object variable or With block variable not set” when attempting to create COM object

StackOverflow https://stackoverflow.com/questions/202662

  •  03-07-2019
  •  | 
  •  

Question

I have a VB6 dll that is trying to create a COM object using the following line of code:

Set CreateObj = CreateObject("OPSValuer.OPSValue")

However this fails with the error "Object variable or With block variable not set".

I can see OPSValuer.OPSValue in dcomcnfg and it appears to be registered fine. Does anyone have any ideas about what may be causing the problem?

Was it helpful?

Solution

DMKing is right about OleView. Also try looking at the control in Dependency Walker, any missing dependencies should come quickly to the surface.

Since this is a DCom component there also may be something failing in the components constructor, if anything fails in the constructor you will get that error. Is this a local DCom object or something running on another tier?

Instead of CreateObject try instantiating it with a standard New and see if it gives you a different error. Adding the reference itself may help out with determining that error. Is there a reason you are using late binding, rather than early binding?

OTHER TIPS

It's possible that the class you are trying to instantiate is not installed correctly or is missing some dependencies. If you have access to OLE View, you can try instantiating that class outside of VB. If it won't instantiate then you have a bad installation or missing dependency. OLE View ships with Visual Studio, search for OleView.exe on your system.

It was located here on my system: D:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin

The error may be thrown within the object initializing routine. That I don't find "OPSValuer.OPSValue" on Google makes me think it is custom code that encounters a bug.

Assuming OPSValuer.OPSValue is a component written in VB, this is probably an error raised in the Class_Initialize event of that component. If you have the source of the component it should be easy to debug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top