check and rename a incrementing txt file from a function

  • Thread starter Thread starter brad
  • Start date Start date
B

brad

i have put together the following code. we get a txt file from a plam that
does a cycle count and hotsyncs to a location on the hard drive. i am having
trouble with finding the incremented new file and renaming it to a
consistant file that is linked back to access for futher processing.

thanking you in advance for your time brad.

Private Sub fFileNameChange()
'checks to see if the file has been loaded to the server
'updates the file to the correct file name format for importing into access

Dim strNewFileName, strOldFileName, strNewFile, strOldFile, strMsgBoxTitle1,
strDirName As String
strDirName = "C:\Program Files\Palm\CycleP\On Hand\"
strOldFile = "Inventory*.txt" ' files are incremented by 1 each time by the
palm on a hotsync
strNewFile = "InvCycleCount.txt" ' new file name to be used linked to
access.
strNewFileName = strDirName & strNewFile
strOldFileName = strDirName & strOldFile
strMsgBoxTitle1 = "Palm Cycle HotSync"


'checks to see if file currently exsists and deletes the old file
If Dir(strOldFileName) = "" Then
MsgBox "The Cycle Count file has not been copied to the correct
location." & _
"Please HotSync the Palm and Click this button again.", ,
strMsgBoxTitle1

'deletes last update file if found in the directory and renames
new
ElseIf Dir(strOldFileName) <> "" And Dir(strNewFileName) <> ""
Then
Kill strNewFileName
Name strOldFileName As strNewFileName
MsgBox "The file is ok to use", , strMsgBoxTitle1

'if update file is found rename to the new name
ElseIf Dir(strOldFileName) <> "" And Dir(strNewFileName) = ""
Then
Name Dir(strOldFileName) As Dir(strNewFileName)
MsgBox "The file is ok to use", , strMsgBoxTitle1

End If

End Sub
 
Back
Top