?
Solved

Object Initialized?

Posted on 2001-07-09
4
Medium Priority
?
344 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

765 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