Move files using wildcard characters using Access 2007
Posted on 2011-10-25
I am needing to move files from a folder on a local computer to a folder on the server. The files on the local device are created by that system. The file naming protocol on the local device is to use the patient ID number followed by the time and date that the file was created (ie. 18814_10252011_1052.jpg)
I need the code to find all files in the folder that include the patient's ID number (in the example 18814) and move them to the server so they can be accessed by the database application. To do this I need to modify the following code so that the files are recognized using wildcard characters for the time and date as I won't necessarily know the date or the specific time that the file was created. Thanks.
Dim file As String, sfol As String, dfol As String
file = "18814" & "*.pdf" ' THE SYNTAX HERE IS WHERE I HAVE THE PROBLEM"
sfol = "C:\Patient Files\"
dfol = "Z:\Server\Patient Files\"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(sfol & file) Then
MsgBox sfol & file & " does not exist!", vbExclamation, "Source File Missing"
ElseIf Not fso.FileExists(dfol & file) Then
fso.MoveFile (sfol & file), dfol
MsgBox dfol & file & " already exists!", vbExclamation, "Destination File Exists"