Solved

Object Not Valid

Posted on 2009-07-13
2
148 Views
Last Modified: 2012-05-07
Experts,

In the attached subroutine, I'm checking to see if my main database object is Nothing so that it doesn't test for whether or not it's closed.  However, I get an error sometimes when I run the program because it says the object is "not valid" or "no longer set".  Isn't that what I'm testing for to begin with?  If the object is "not valid", how is it getting to the "Close" statement?
Public Sub BackUpDatabase()
 

    frmMessage.lblMessage.Caption = "Backing up database..."

    frmMessage.Show
 

    Dim SrcFile As String, DestFile As String
 

    If Not gdbKnowledgeTracker Is Nothing Then

        gdbKnowledgeTracker.Close

    End If

    

    SrcFile = App.Path & "\Data\KnowledgeTracker.mdb"

    DestFile = App.Path & "\Data\KnowledgeTracker_BAK.mdb"
 

    Call FileCopy(SrcFile, DestFile)

    

    

    Set gdbKnowledgeTracker = OpenDatabase(App.Path + "\Data\KnowledgeTracker.mdb")

            

    Unload frmMessage
 

End Sub

Open in new window

0
Comment
Question by:NigelRocks
2 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 24842219
You may use a global variable blnFlag As Boolean=False to track your object  gdbKnowledgeTracker

When you set the object reassign blnFlag = True
0
 
LVL 2

Accepted Solution

by:
everkleer earned 500 total points
ID: 24843922
I think you need something like IsObject(gdbKnowledgeTracker) instead of gdbKnowledgeTracker is Nothing.  I forget exactly but I've wasted hours on a similar issue before.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now