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