Solved

Object Initialized?

Posted on 2001-07-09
4
337 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now