[COLOR=blue]Function[/COLOR] StandardDGQuesImages()
[COLOR=blue]On Error Resume Next[/COLOR]
[COLOR=blue]Dim[/COLOR] rst [COLOR=blue]As[/COLOR] DAO.Recordset [COLOR=darkgreen]'Declare rst as DAO Recordset[/COLOR]
[COLOR=blue]Dim[/COLOR] DB [COLOR=blue]As[/COLOR] Database [COLOR=darkgreen]'Declare DB as the Database[/COLOR]
[COLOR=blue]Dim[/COLOR] FS [COLOR=blue]As[/COLOR] FileSystemObject [COLOR=darkgreen]'Declare the File System Object[/COLOR]
[COLOR=blue]Dim[/COLOR] Folder [COLOR=blue]As[/COLOR] Folder [COLOR=darkgreen]'Declare the Folder Object[/COLOR]
[COLOR=blue]Dim[/COLOR] File [COLOR=blue]As[/COLOR] File [COLOR=darkgreen]'Declare the File Object[/COLOR]
[COLOR=blue]Dim[/COLOR] TifFilePath [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the TifFilePath as a string[/COLOR] [COLOR=darkgreen]variable[/COLOR]
[COLOR=blue]Dim[/COLOR] NameOfFile [COLOR=darkgreen]'Declare the NameOfFile variable[/COLOR]
[COLOR=blue]Dim[/COLOR] strTemp [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the strTemp as a string v[/COLOR]ariable
[COLOR=blue]Dim[/COLOR] FileLoc [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the FileLoc as a string var[/COLOR]iable
[COLOR=blue]Dim[/COLOR] TopFolder [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the TopFolder as a string variable[/COLOR]
[COLOR=blue]Dim[/COLOR] FormCode [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the FormCode as a string variable[/COLOR]
[COLOR=blue]Dim[/COLOR] PlanNumber [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the PlanNumber as a string variable[/COLOR]
[COLOR=blue]Dim[/COLOR] BatchID [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the BatchID as a string variable[/COLOR]
[COLOR=blue]Dim[/COLOR] ImagePath [COLOR=blue]As[/COLOR] String [COLOR=darkgreen]'Declare the ImagePath a string variable[/COLOR]
[COLOR=blue]Set[/COLOR] DB = CurrentDb [COLOR=darkgreen]'Set DB as the current Database[/COLOR]
[COLOR=blue]Set[/COLOR] FS = CreateObject("Scripting.FileSystemObject") [COLOR=darkgreen]'Set the File System Object[/COLOR]
[COLOR=blue]Set[/COLOR] rst = DB.OpenRecordset("tblStdD&GNewBrandAdd") [COLOR=darkgreen]'Set the rst to the tblStdD&GNewBrandAdd table[/COLOR]
[COLOR=blue]Do While Not[/COLOR] rst.EOF [COLOR=darkgreen]'Loop until the end of the file[/COLOR]
[COLOR=blue]If Not[/COLOR] rst.EOF [COLOR=blue]Then[/COLOR]
FormCode = rst![strFormCode] [COLOR=darkgreen]'Assign the field strFormCode to the variable FormCode[/COLOR]
PlanNumber = rst![strPlanNumber] [COLOR=darkgreen]'Assign the field strPlanNumber to the variable PlanNumber[/COLOR]
BatchID = rst![strBatchID] [COLOR=darkgreen]'Assign the field strBatchID to the variable BatchID[/COLOR]
ImagePath = rst![strImagePath] [COLOR=darkgreen]'Assign the field strImagePath to the variable ImagePath[/COLOR]
TopFolder = Mid(ImagePath, 4, 37) [COLOR=darkgreen]'Assign the Top Folder starting point i.e. 20120114\00040243_DOMESTICGENERAL_001[/COLOR]
[COLOR=darkgreen]'Set the tif file path here [the location where tif files are stored]i.e J:\20120124\00040243_DOMESTICGENERAL_001[/COLOR]
TifFilePath = "J:\" & TopFolder
[COLOR=darkgreen]'If the text file folder can't be read then, stop running[/COLOR]
[COLOR=blue]If Not[/COLOR] FS.FolderExists(TifFilePath) [COLOR=blue]Then[/COLOR]
MsgBox "Folder Doesn't Exist", , "Reading Tif Files"
[COLOR=blue]End[/COLOR] [COLOR=darkgreen]'End the process[/COLOR]
[COLOR=blue]End If[/COLOR]
[COLOR=darkgreen]'Get the path to the tif files in this case J:\20120124\00040243_DOMESTICGENERAL_001[/COLOR]
[COLOR=blue]Set[/COLOR] Folder = FS.GetFolder(TifFilePath)
[COLOR=darkgreen]'Loops through Folders looking for Files[/COLOR]
[COLOR=blue]For Each[/COLOR] File [COLOR=blue]In[/COLOR] Folder.Files
[COLOR=darkgreen]'Get the tif file name[/COLOR]
NameOfFile = GetAttr("File.Name")
[COLOR=darkgreen]'If the file found has a ".tif" extension then[/COLOR]
[COLOR=blue]If[/COLOR] Right(File.Name, 4) = ".tif" [COLOR=blue]Then[/COLOR]
[COLOR=darkgreen]'Assign the text file name to the strTemp variable i.e. 00040243_DOMESTICGENERAL_001_10.tif[/COLOR]
strTemp = Mid$(File.Name, InStrRev(File.Name, "\") + 1)
[COLOR=darkgreen]'Assign the Folder and File.Name to the FileLoc variable i.e. J:\20120124\00040243_DOMESTICGENERAL_001\00040243_DOMESTICGENERAL_001_10.tif[/COLOR]
FileLoc = Folder & "\" & File.Name
[COLOR=blue]If[/COLOR] FileLoc = ImagePath [COLOR=blue]Then[/COLOR]
[COLOR=darkgreen]'Copy tif file to new location and rename[/COLOR]
[COLOR=darkgreen] FS.CopyFile Folder & "\" & strTemp, "H:\John Lee\StdDGImages" & "\" & FormCode & "\" & PlanNumber & ".tif"[/COLOR]
[COLOR=blue]End If[/COLOR]
[COLOR=blue] End If[/COLOR]
DoEvents
[COLOR=darkgreen]'Indicates in the progress bar the file being worked on[/COLOR]
DoCmd.Echo True, "Copying Std Ques Files to New Location: " & Folder & "\" & strTemp & "To: " & "H:\John Lee\StdDGImages" & "\" & FormCode & "\" & PlanNumber & ".tif"
[COLOR=blue]Next[/COLOR]
[COLOR=blue]End If[/COLOR]
[COLOR=darkgreen]'Move to the next record[/COLOR]
rst.MoveNext
[COLOR=blue]Loop[/COLOR]
rst.Close
[COLOR=blue]Set[/COLOR] rst = [COLOR=blue]Nothing[/COLOR]
[COLOR=blue]Set[/COLOR] DB = [COLOR=blue]Nothing[/COLOR]
[COLOR=blue]End Function[/COLOR]