Solved

Object Initialized?

Posted on 2001-07-09
4
341 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:jrcp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
chandukb earned 50 total points
ID: 6265966
if not qMyQuery is nothing then
   Set qMyQuery
else
   'object has been set, so do your stuff
end if

Chandu
 
0
 
LVL 2

Expert Comment

by:chandukb
ID: 6265975
Sorry,

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

Chandu
0
 
LVL 2

Expert Comment

by:chandukb
ID: 6265982
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

0
 
LVL 6

Expert Comment

by:andyclap
ID: 6267205
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).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question