|
|
Question : How to populate MS Access temp table using VBA
|
|
- I am trying to create a temporary table (tblTempAllocs) on the local hard drive, populated with data from the linked table tblValAllocs. The data incorporated in the temporary table should be selected based on the dates PPStartDate (mm/dd/yyyy) and PPEndDate that user should be prompted for. So far I have only created the Temporary Table. Could you please help me with the rest of the code? The code is VBA in the MS Access Database.
Public Function CreateTable()
' Delete table if it exists On Error Resume Next DoCmd.RunSQL "DROP TABLE tblTempAllocs "
'Create new table Dim db As DAO.Database Dim tdf As TableDef Dim fld As Field
Set db = CurrentDb()
Set tdf = db.CreateTableDef("tblTempAllocs ") Set fld = tdf.CreateField("Employee", dbText, 63) tdf.Fields.Append fld tdf.Fields.Refresh Set fld = tdf.CreateField("Activity", dbText, 92) tdf.Fields.Append fld tdf.Fields.Refresh Set fld = tdf.CreateField("ReportedHours", dbLong) tdf.Fields.Append fld tdf.Fields.Refresh Set fld = tdf.CreateField("PayPeriod", dbText, 2) tdf.Fields.Append fld tdf.Fields.Refresh Set fld = tdf.CreateField("PPStartDate", dbText, 30) tdf.Fields.Append fld tdf.Fields.Refresh Set fld = tdf.CreateField("PPEndDate", dbText, 30) tdf.Fields.Append fld tdf.Fields.Refresh db.TableDefs.Append tdf db.TableDefs.Refresh
MsgBox "Table: Table tblTempAllocs created" db.Close
End Function
|
Answer : How to populate MS Access temp table using VBA
|
|
if you are creating a table withe same fields as the source table, you can simply do this
On Error Resume Next DoCmd.RunSQL "DROP TABLE tblTempAllocs "
dim sql sql="SELECT * INTO tblTempAllocs" sql=sql & " FROM tblValAllocs" sql=sql & " Where [PPStartDate]=[Enter Start Date] And [PPEndDate]=[Enter End Date]"
currentdb.execute sql
|
|
|
|
|