Solved

Copy table before Importing new table

Posted on 2016-11-01
3
35 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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now