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


Random Solutions  
  •  .mdb vs .adp front end with SQL server backend
  •  How to Encrypt FullText Search Column Value using MS SQL Server 2005?
  •  can i move the $hf_mig$ file to the D: drive?
  •  What is the best internet security and antivirus program?
  •  Installing a root certificate on cell phone for EAS
  •  Can you validate email addresses without SENDING it to the address? We want to confirm before sending bulk marketing emails. Some will be old and outdated.
  •  MS Project 2003 - What is the best method for changing a project and all associated tasks to a 7-day calendar?
  •  I jthink you must have the answer to my question as well.  How can I make the footnote separator (in Word 2007) be closer to the footnote text? It has 6 paragraph breaks before footnote text now.
  •  system unable double click to access C drive
  •  Small Business Server 2003 - Changing Hard Drive Letter.
  •  
    programming4us programming4us