How to export a table by utilizing a keyword (1 Viewer)

jgier

Registered User.
Local time
Today, 06:37
Joined
Mar 19, 2012
Messages
21
Hi Everyone,

I'm working on a automation process that will be pulling a csv file, placing the data into a table with the current date. I want to export the table into another database, but how do I do that since the date will always be changing? The coding below shows the import csv file and table process.

Public Sub ImportFile()
Dim strPath As String
Dim strTable As String
Dim strSpec As String

DoCmd.SetWarnings False

strPath = "C:\Documents and Settings\XXXX\Desktop\CB_Feed_Upload\CB_UPLOAD.csv"

strTable = "tblMasterFile" & Format(Date, "YYYYMMDD")

strSpec = "ImportSpec"

DoCmd.TransferText acImportDelim, strSpec, strTable, strPath, True

I need to export that table into another database, but the name will appear like this "tblMasterFile20120515". Am I able to utilize a keyword such as tblMasterFile?

Thank you in advance.
 

jgier

Registered User.
Local time
Today, 06:37
Joined
Mar 19, 2012
Messages
21
If anyone ever runs into this issue, here is my thought process of how I solved my issue. I created a set of If Then Else statements. Below is an example set of code.

'Creates the current date placed on table that is being transferred

strTableDate = Format(Date, "YYYYMMDD")

'This command will create the table tblMaster(With current date) and place the table into the current database.

DoCmd.TransferDatabase acExport, "Microsoft Access", "L:\Example\User\ACCESS DATABASES\COM-R TPC UPLOAD\CB_DAILY_FEED(REDESIGN).accdb", acTable, "tblMasterFile", "tblMaster" + strTableDate, False

'If statement will create a logic if today's date is equal to the same month but different year and day, then the table will be placed into the given file path/designated month folder

If strTableDate = Format(Date, "YYYY01DD") Then

'This set of command will export data from tblMasterFile and place it into the file path below with the current date

DoCmd.TransferDatabase acExport, "Microsoft Access", ""L:\Example\Test\Run\CB_Archive_Database\January\CB_Archive01.accdb", acTable, "tblMasterFile", "tblMasterFile" & Format(Date, "YYYYMMDD"), False
Else

If strTableDate = Format(Date, "YYYY02DD") Then

'This set of command will export data from tblMasterFile and place it into the file path below with the current date

DoCmd.TransferDatabase acExport, "Microsoft Access", "L:\Example\Test\Run\CB_Archive_Database\February\CB_Archive02.accdb", acTable, "tblMasterFile", "tblMasterFile" & Format(Date, "YYYYMMDD"), False

End If
End If
 

Users who are viewing this thread

Top Bottom