troubleshooting Question

Create an ACCESS table from Excel

Avatar of Sandra Smith
Sandra SmithFlag for United States of America asked on
Microsoft ExcelMicrosoft ApplicationsMicrosoft Development
6 Comments1 Solution643 ViewsLast Modified:
I seem to be going in circles.  I get some to work and then it doesn't.  The below partially works - however, the code between the asterisk lines does not.  I need to create the table in the databased from Excel, but it does not recognie my appACCESS.

Sandra

Public Sub OpenKeyMetricsForm()
'Opens Key Metrics form for data entry into the database
On Error Resume Next
Dim strPath As String
Dim appAccess As Access.Application
Dim tdfTable As DAO.TableDef
Dim dteDate As Date
Dim gstrUserId As String
Dim intDeptID As Long

intDeptID = ThisWorkbook.Worksheets("MainMenu").Range("DeptID")
gstrUserId = VBUserName()
dteDate = BOM(Date) - 1

strPath = ThisWorkbook.Worksheets("MainMenu").Range("B1")

    Set appAccess = CreateObject("Access.Application")
   ' Open the Employees table in the Northwind database
   appAccess.OpenCurrentDatabase strPath
   
'*********************************************************************************************************************
 'Create table in database

Set tdfTable = appAccess.CreateTableDef("tblTEMPKMQuantities")
With tdfTable
    .Fields.Append .CreateField("KMID", dbText)
    .Fields.Append .CreateField("Quantity", dbLong)
    .Fields.Append .CreateField("Description", dbText)
    .Fields.Append .CreateField("KMDate", dbDate)
    .Fields.Append .CreateField("UserID", dbText)
    CurrentDb.TableDefs.Append tdfTable
End With

'Insert KM information
DoCmd.RunSQL "INSERT INTO tblTEMPKMQuantities ( KMID, Description, KMDate, UserID)" & _
    "SELECT tblKM.KMID, tblKM.Description, #" & dteDate & "#, '" & gstrUserId & "' " & _
    "FROM tblKM WHERE tblKM.Active = -1 AND tblKM.DeptID = " & DeptID
'*********************************************************************************************************************
   
   ' Open KM form
    ' appAccess.DoCmd.OpenForm "frmKeyMetricsQtys", acViewNormal
     appAccess.DoCmd.Close acForm, "frmTimeSheet"
     appAccess.Visible = True
     appAccess.DoCmd.OpenForm "frmKeyMetricsQty", acViewNormal

End Sub
ASKER CERTIFIED SOLUTION
ukerandi

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 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 6 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