troubleshooting Question

Check for a table from Excel that may exit in ACCESS 2003

Avatar of Sandra Smith
Sandra SmithFlag for United States of America asked on
Microsoft ExcelMicrosoft ApplicationsMicrosoft Development
3 Comments1 Solution384 ViewsLast Modified:
I have a function, fntDoesObjectExit, in an ACCESS 2003 database.  It checks for the object, in this case a table, and if it exsits, deletes it.  But how can I get Excel to run this line of code?  I need it to run just before the table creation code in an Excel module.  what I have now works, if the table does not exist, but if does, the code throws an error.  Below is the code at it stands now.

Sandra

    'Set database name and DB connection string--------
    strDBPath = ThisWorkbook.Worksheets("MainMenu").Range("B1")
    '==================================================
   
    strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
 
    'Connect Database; insert a new table
    Set objConnection = New ADODB.Connection
    With objConnection
        .Open strConnectString
       
   'HOW TO GET THIS RUN??
''If fntDoesObjectExist("tblTEMPKMQuantitites", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPKMQuantities")
       
       
        .Execute "CREATE TABLE tblTEMPKMQuantities ([KMID] text(10), " & _
                 "[Quantity] Long, " & _
                 "[Description] text(150), " & _
                 "[KMDate] Date, " & _
                 "[UserID] text(15))"
                 
        .Execute "INSERT INTO tblTEMPKMQuantities ( KMID, Description, KMDate, UserID)" & _
                 "SELECT tblKM.KMID, tblKM.Description, #" & dteDate & "#, '" & gstrUserId & "' " & _
                 "FROM tblKM WHERE tblKM.Active = -1 AND tblKM.DeptID = " & intDeptID
    End With
 
    Set objConnection = Nothing
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros