Link to home
Start Free TrialLog in
Avatar of NigelRocks
NigelRocks

asked on

Object Not Valid

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

Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

You may use a global variable blnFlag As Boolean=False to track your object  gdbKnowledgeTracker

When you set the object reassign blnFlag = True
ASKER CERTIFIED SOLUTION
Avatar of everkleer
everkleer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial