Solved

Copy table before Importing new table

Posted on 2016-11-01
3
50 Views
Last Modified: 2016-11-02
Experts, before I import "Import_FC.xlsm", I first need to copy the tblImport_FC as it resides in the db, but I would like to append the current date to the end of the tbl name.  
ie tblImport_FC ==>tblImport_FC_161102

How can I modify the below to first copy the tblImport_FC as append the date as described?

Private Sub cmdImport_Click()

         Dim strName As String
         Dim xl As Object
            Set xl = CreateObject("Excel.Application")
            xl.Workbooks.Open ("C:\Users\johnsoat\Desktop\Import_FC.xlsm")
            xl.Run "Transpose"
            xl.ActiveWorkbook.Close (True)
            xl.Quit
            Set xl = Nothing
            CurrentDb.Execute "delete * from [Import_FC]"
            strName = "Transpose"

        DoCmd.TransferSpreadsheet acImport, , "Import_FC", "C:\Users\johnsoat\Desktop\Import_FC.xlsm", True, strName & "!"


End Sub

Open in new window

0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 41869623
Hi,

pls try
Private Sub cmdImport_Click()

         Dim strName As String
         Dim xl As Object
            Set xl = CreateObject("Excel.Application")
            xl.Workbooks.Open ("C:\Users\johnsoat\Desktop\Import_FC.xlsm")
            xl.Run "Transpose"
            xl.ActiveWorkbook.Close (True)
            xl.Quit
            Set xl = Nothing
            CurrentDb.Execute  "select * into  [Import_FC_" & format(date,"yyMMdd") & "] from [Import_FC]"
            CurrentDb.Execute "delete * from [Import_FC]"
            strName = "Transpose"

        DoCmd.TransferSpreadsheet acImport, , "Import_FC", "C:\Users\johnsoat\Desktop\Import_FC.xlsm", True, strName & "!"


End Sub

Open in new window

Regards
0
 
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 250 total points
ID: 41870014
Why do you feel the need to create multiple tables in your database with identical structure and different names?  Is this for some archive purpose?  If so, you might want to consider a single archive table that includes all of the other field of the original table and an ArchiveDate.  Then you can simply write an append query to append all of the current records to that Archive table with the current date added.  This would rapidly grow, but would give you the ability to quickly compare "similar" records across time as well as restore from the Archive if it is necessary.

Just my 2 cents!

Dale
0
 

Author Comment

by:pdvsa
ID: 41870364
Dale that is a brilliant idea.  I am going to close this question and award pts Rgonzo because his solution works and i might need it later.  Any objections let me know
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question