Brad Marks
BradM at blackforestltd.com
Fri Jun 24 16:31:27 CDT 2011
Gary, Thanks! Brad -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gary Kjos Sent: Friday, June 24, 2011 8:07 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] How to Rename a flat file with Access VBA Use the Name statement ------------------------------------------------------------------------ --------------- Renames a disk file, directory, or folder. Syntax Name oldpathname As newpathname The Name statement syntax has these parts: Part Description oldpathname Required. String expression that specifies the existing file name and location-may include directory or folder, and drive. newpathname Required. String expression that specifies the new file name and location-may include directory or folder, and drive. The file name specified by newpathname can't already exist. Remarks Both newpathname and oldpathname must be on the same drive. If the path in newpathname exists and is different from the path in oldpathname, the Name statement moves the file to the new directory or folder and renames the file, if necessary. If newpathname and oldpathname have different paths and the same file name, Name moves the file to the new location and leaves the file name unchanged. Using Name, you can move a file from one directory or folder to another, but you can't move a directory or folder. Using Name on an open file produces an error. You must close an open file before renaming it. Name arguments cannot include multiple-character (*) and single-character (?) wildcards. ------------------------------------------------------------ Examples ------------------------------------------------------------ This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. Dim OldName, NewName OldName = "OLDFILE": NewName = "NEWFILE" ' Define filenames. Name OldName As NewName ' Rename file. ' In Microsoft Windows: OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE" Name OldName As NewName ' Move and rename file. ' On the Macintosh: OldName = "HD:MY FOLDER:OLDFILE": NewName = "HD:YOUR FOLDER:NEWFILE" Name OldName As NewName ' Move and rename file. ----------------------------------------------------------------------- Here's some of my code that does that ---------------------------------------------------------------------- Dim strImportPath As String Dim strBackupPath As String Dim strCheckFile As String strBackupPath = Me!txtBackupPathAndFile strImportPath = Me!txtImportPathAndFilename strCheckFile = Dir(strImportPath) If Len(strCheckFile) < 1 Then Me!txtMessage = "Import file not found - Import UNSUCCESSFULL!" MsgBox "Import file not found - Import UNSUCCESSFULL!" GoTo Exit_cmdProcessWithSeek_Click End If Me!txtMessage = "Commencing import Process. " Me.Repaint Name strImportPath As strBackupPath --------------------------------------------- GK On Fri, Jun 24, 2011 at 7:44 AM, Brad Marks <BradM at blackforestltd.com> wrote: > All, > > We just installed some EDI software that creates a number of flat files. > > There is one file that is a text file but the extension is .tbl > > I would like to link to this file with Access 2007, but I am running > into problems because of the .tbl extension. > > For the short term, I am simply renaming the file outside of Access. > This works, but I would prefer to do the renaming inside of Access. > > Is there a way to use VBA to rename flat files. > > Example - > Old name = C:\EDI\Outbound.tbl > New name = C:\EDI\Outbound.txt > > I figure that this is pretty easy to do, but I have never done it and I > have not found an example of how to do it. > > Thanks in advance for your assistance. > > Brad > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.