Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Object Not Valid

Posted on 2009-07-13
2
Medium Priority
?
155 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 31

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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

782 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