Link to home
Start Free TrialLog in
Avatar of jrcp
jrcpFlag for Afghanistan

asked on

Object Initialized?

Is there a way to check to see if an object has been initialized before trying to reference it?

eg.

Calling
If qMyQuery.recordcount then
  do something
end if

before qMyQuery has been set.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of chandukb
chandukb

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
Avatar of chandukb
chandukb

Sorry,

If qMyQuery Is Nothing then
  'Set qMyQuery
else
  'Object has been set, do processing
end if

Chandu
As an example, Here is how I open my connection

If moConnection Is Nothing Then 'Connection not yet open
    Set moConnection = New ADODB.Connection
    moConnection.CursorLocation = adUseClient
Else
   'Connection already opened
   'I call my processing procedures
end if

Hope this helps

Chandu

Well, you've got to remember that you're checking whether your object variable has been set to the object here, not whether the object itself is instatiated.
There's no real way of doing this, apart from some global shared storage somewhere you can write a flag to. Mind you, most of the time you'll want to do this to check instatiation of a module/global scope variable so chandu's comments are perfectly valid (and indeed I use this sort of thing all the time in my code).