Private Sub cmdImportSales_Click()
Dim dbs As Database, tbl As TableDef, fld As Field
Dim dteTopDate As Date
DoCmd.SetWarnings False
Set dbs = CurrentDb
Set tbl = dbs.CreateTableDef("tblTopDate")
Set fld = tbl.CreateField("TopDate", dbDate)
tbl.Fields.Append fld
dbs.TableDefs.Append tbl
dbs.TableDefs.Refresh
'Find top date in the existing tblSales table
dteTopDate = DMax("InvDate", "[tblSales]")
'This is a test to verify that the maximum date is being selected
MsgBox dteTopDate
'Add the Top Date to the newly created tblTopDate table
DoCmd.RunSQL "INSERT INTO [tblTopDate] ([TopDate]) VALUES (dteTopDate)"
End Sub
|