Solved

Object Not Valid

Posted on 2009-07-13
2
147 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

708 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

14 Experts available now in Live!

Get 1:1 Help Now