Results 1 to 7 of 7
  1. #1
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95

    Problem with DoCMD.DeleteObject or IsObject

    I'm trying to determine my error in this coding. I am looking to check if a table exists, if it does, delete it and import a new table that has the same name as the one I checked for (in this case, check for CPPS, delete it if it exists and add a new table named CPPS from a form value using import specs).



    It appears that the isobject is not working, because it tries to execute the code even if there is no CPPS table. It also appears to duplicate the imported table (i.e. if the CPPS table has 100 records, it creates a table with 200 records, each one duplicated once).

    Here is the code:

    On Error GoTo CPPSnxt
    If IsObject(CurrentDb.TableDefs("CPPS")) = True Then
    DoCmd.DeleteObject acTable, "CPPS"
    End If
    CPPSnxt:
    DoCmd.TransferText acImportDelim, "CPPS SEPS", "CPPS", CPPStxt.Value
    Resume Next
    End If

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    p5,

    an easy way to check this is to check the error number. example:
    Code:
    strname = currentdb.tabledefs("tablename").name
    
    if err.number=3265 then
       'TABLE DOESN'T EXIST
    else
       'table is here.  delete it!
    end if
    if the table is present, the name prop will be passed to the variable, and the err.number will remain at 0, where it always starts in a procedure.

  3. #3
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    I tried this code:

    Code:
            If Err.Number = 3265 Then
                GoTo CPPSnxt
            Else
                DoCmd.DeleteObject acTable, "CPPS"
            End If
    CPPSnxt:    DoCmd.TransferText acImportDelim, "CPPS SEPS", "CPPS", CPPStxt.Value
    But now I'm getting error 7874 (can't find CPPS object) when I execute the code.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by P5C768 View Post
    I tried this code:

    Code:
            If Err.Number = 3265 Then
                GoTo CPPSnxt
            Else
                DoCmd.DeleteObject acTable, "CPPS"
            End If
    CPPSnxt:    DoCmd.TransferText acImportDelim, "CPPS SEPS", "CPPS", CPPStxt.Value
    But now I'm getting error 7874 (can't find CPPS object) when I execute the code.
    probably because you're not using my code. different syntax yields different errors, right? YES.

    concept is the same. the table is probably not there.

  5. #5
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    Using your code, I still get error 3265 when strname is set, it never goes to the if statement to get the err.number.

    This seems to work:

    Code:
     
    On Error GoTo CPPSnxt
        IsObject (CurrentDb.tabledefs("CPPS"))
            
    CPPSnxt:    If Err.Number = 3265 Then
                    DoCmd.TransferText acImportDelim, "CPPS SEPS", "CPPS", CPPStxt.Value
                Else
                    DoCmd.DeleteObject acTable, "CPPS"
                    DoCmd.TransferText acImportDelim, "CPPS SEPS", "CPPS", CPPStxt.Value
                End If

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you have to set your options P5. BREAK ON UNHANDLED ERRORS is what you have to have set! good luck!

  7. #7
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    It looks like the actual problem here was that I was trying to use On Error Goto <label> four times in the same procedure. Researching around a little more, I found that VBA doesn't let you do this. I solved my problem both by using the code above and by separating my code in to four separate procedures and than calling each of them in an on click event. Thanks for the help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  2. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 AM
  3. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  4. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums