Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Object Not Valid

Posted on 2009-07-13
2
Medium Priority
?
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

715 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