Export and Rename A File

Learn2010

Registered User.
Local time
Today, 01:17
Joined
Sep 15, 2010
Messages
415
I posted the question below but may have another option that is easier. I can export a table to a text file. I'll call it MyTextFile.txt. Now that I have the file exported to C:\PSWaiverFiles\MyTextFile.txt, I would like to rename it to a control on one of my forms. The control is Forms!frmDailyLogOptions!WaiverFile. The data in that field is something like M1111111.001. How do I rename C:\PSWaiverFiles\MyTextFile.txt to C:\PSWaiverFiles\M1111111.001?

I am familiar with vbs scripts and the Shell feature a little.


Thanks again.

PREVIOUS POSTING
I will be sending a flat file once a month by uploading it to the internet. It has a very explicit layout. I create a table, export it to a folder, and rename it. The naming convention is as follows:

M[ContractNumber].nnn

The nnn is a sequential set of numbers. I have a table that I use to create this file name with an update query. After running the process I will update the nnn number by 1 each time I send it. For example, the first file would be M111111.001. The second file would be M111111.002, and so on.

In testing the process, I put the table behind a form with the control buttons and added the field with the file name to the form. After testing I will hide the field. Here are the components of the process.

Form – frmDailyLogOptions

Table - tblWaiverBillingFileName

Control Name on Form – WaiverFile

Output Folder – C:\PSWaiverFiles\

I need help tweaking the code for the process. I have no trouble creating text files with this process. I am using the following to create and export the file.

DoCmd.TransferText acExportFixed, "WaiverFiles", "tblWaiverBilling", "C:\PSWaiverFiles\" & Forms!frmDailyLogOptions!WaiverFile, False, ""

I get a message that says “Cannot update. Database or object is read-only.” What do I need to do?

Thank you.
 
Last edited:
Will this work for you?

Code:
dim stFileLoc as String
...
stFileLoc = "[SIZE=3][FONT=Calibri]C:\PSWaiverFiles\"[/FONT][/SIZE]
FileCopy stFileLoc & "[SIZE=3][FONT=Calibri]MyTextFile.txt"[/FONT][/SIZE], [SIZE=3][FONT=Calibri]stFileLoc & Forms!frmDailyLogOptions!WaiverFile[/FONT][/SIZE]
From the help menu:
FileCopy source, destination
 
That worked. Thanks so much. I really appreciate that.
 

Users who are viewing this thread

Back
Top Bottom