Solved

Copy table before Importing new table

Posted on 2016-11-01
3
40 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
3 Comments
 
LVL 49

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 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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