Good day,
I'm hoping someone can help me here, I two sets of code which are almost identicle, one works fine but I can't work out why the other one doesn't. The code structure for both sets of code are the same with some differences with regards to where they get their information from and where they put and rename the images, please see below
The above code works fine every single time
The line in red is where this code keeps falling over, it's saying that it can't find the tif files although the files do exist, I've checked and double checked, I just stuck on trying to work out why this is, the only differences between this code structure and the first one above are shown in blue in this bit of code, so my thoughts are that this should work just like the other code, but not so far.
Hopefully someone can spot what may be wrong with the second code block.
Assistance/pointers would be most gratefully accepted.
Regards
John
I'm hoping someone can help me here, I two sets of code which are almost identicle, one works fine but I can't work out why the other one doesn't. The code structure for both sets of code are the same with some differences with regards to where they get their information from and where they put and rename the images, please see below
Code:
[FONT=Times New Roman]Function SkyQuesImages()[/FONT]
[FONT=Times New Roman]On Error Resume Next[/FONT]
[FONT=Times New Roman]'-------------------------------------------[/FONT]
[FONT=Times New Roman]'References:[/FONT]
[FONT=Times New Roman]'Visual Basic For Applications[/FONT]
[FONT=Times New Roman]'Microsoft Access 9.0 Object Library[/FONT]
[FONT=Times New Roman]'OLE Automation[/FONT]
[FONT=Times New Roman]'Microsoft ActiveX Data Objects 2.1 Library[/FONT]
[FONT=Times New Roman]'Microsoft Scripting Runtime[/FONT]
[FONT=Times New Roman]'Microsoft DAO 3.6 Object Library[/FONT]
[FONT=Times New Roman]'-------------------------------------------[/FONT]
[FONT=Times New Roman] Dim DB As Database [/FONT]
[FONT=Times New Roman] Dim File As File [/FONT]
[FONT=Times New Roman] Dim FileLoc As String [/FONT]
[FONT=Times New Roman] Dim Folder As Folder [/FONT]
[FONT=Times New Roman] Dim FormCode As String [/FONT]
[FONT=Times New Roman] Dim FS As FileSystemObject [/FONT]
[FONT=Times New Roman] Dim ImagePath As String [/FONT]
[FONT=Times New Roman] Dim NameOfFile [/FONT]
[FONT=Times New Roman] Dim Agent As String [/FONT]
[FONT=Times New Roman] Dim SchemeCode As String [/FONT]
[FONT=Times New Roman] Dim PlanNumber As String [/FONT]
[FONT=Times New Roman] Dim SchRef As String [/FONT]
[FONT=Times New Roman] Dim rst As DAO.Recordset [/FONT]
[FONT=Times New Roman] Dim SkyTable [/FONT]
[FONT=Times New Roman] Dim strTemp As String [/FONT]
[FONT=Times New Roman] Dim TifFilePath As String [/FONT]
[FONT=Times New Roman] Dim TopFolder As String [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] Set DB = CurrentDb [/FONT]
[FONT=Times New Roman] Set FS = CreateObject("Scripting.FileSystemObject") [/FONT]
[FONT=Times New Roman] Set rst = DB.OpenRecordset("tblSky") [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] SkyTable = DCount("*", "tblSky") [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] If SkyTable > 0 Then [/FONT]
[FONT=Times New Roman] Do While Not rst.EOF [/FONT]
[FONT=Times New Roman] If Not rst.EOF Then [/FONT]
[FONT=Times New Roman] FormCode = rst![strFormType] [/FONT]
[FONT=Times New Roman] Agent = rst![strAgentNo] [/FONT]
[FONT=Times New Roman] SchemeCode = rst![strSchemeCode] [/FONT]
[FONT=Times New Roman] PlanNumber = rst![strPlanNumber] [/FONT]
[FONT=Times New Roman] SchRef = Agent & "_" & SchemeCode & PlanNumber [/FONT]
[FONT=Times New Roman] ImagePath = rst![strImagePath] [/FONT]
[FONT=Times New Roman] TopFolder = Mid(ImagePath, 4, 25) [/FONT]
[FONT=Times New Roman] TifFilePath = "J:\" & TopFolder [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] If Not FS.FolderExists(TifFilePath) Then [/FONT]
[FONT=Times New Roman] MsgBox "Folder Doesn't Exist", , "Reading Tif Files" [/FONT]
[FONT=Times New Roman] End [/FONT]
[FONT=Times New Roman] End If[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] Set Folder = FS.GetFolder(TifFilePath) [/FONT]
[FONT=Times New Roman] For Each File In Folder.Files [/FONT]
[FONT=Times New Roman] NameOfFile = GetAttr("File.Name") [/FONT]
[FONT=Times New Roman] strTemp = Mid$(File.Name, InStrRev(File.Name, "\") + 1) [/FONT]
[FONT=Times New Roman] FileLoc = Folder & "\" & File.Name [/FONT]
[FONT=Times New Roman] If FileLoc = ImagePath Then [/FONT]
[FONT=Times New Roman] FS.CopyFile Folder & "\" & strTemp, "M:\Customer Satisfaction\StdDGImages" & "\" & FormCode & "\" & SchRef & ".tif" [/FONT]
[FONT=Times New Roman] End If[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] DoEvents [/FONT]
[FONT=Times New Roman] DoCmd.Echo True, "Copying File to New Loc: " & Folder & "\" & strTemp & "To: " & "M:\Customer Satisfaction\StdDGImages" & "\" & FormCode & "\" & SchRef & ".tif" [/FONT]
[FONT=Times New Roman] Next [/FONT]
[FONT=Times New Roman] End If[/FONT]
[FONT=Times New Roman] rst.MoveNext [/FONT]
[FONT=Times New Roman] Loop[/FONT]
[FONT=Times New Roman] End If[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] SkyTable = 0 [/FONT]
[FONT=Times New Roman] rst.Close [/FONT]
[FONT=Times New Roman] Set rst = Nothing [/FONT]
[FONT=Times New Roman] Set DB = Nothing [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] DoCmd.Echo True, "Standard DG 2012 Images Organising Process Complete"[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman]End Function[/FONT]
The above code works fine every single time
Code:
[FONT=Times New Roman][SIZE=3]Function BiasiImages()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]On Error Resume Next[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'-------------------------------------------[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'References:[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'Visual Basic For Applications[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'Mircrosoft Access 9.0 Object Library[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'OLE Automation[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'Microsoft ActiveX Data Objects 2.1 Library[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'Microsoft Scripting Runtime[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'Microsoft DAO 3.6 Object Library[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]'-------------------------------------------[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim rst As DAO.Recordset[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim DB As Database[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim FS As FileSystemObject[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim Folder As Folder[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim File As File[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim TifFilePath As String[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim NameOfFile As String[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim strTemp As String[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim FileLoc As String[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Dim TopFolder As String[/SIZE][/FONT]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim Title As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim Initials As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim Surname As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim Customer As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim VerifiedDate As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim ImageLoc As String[/FONT][/SIZE][/COLOR][/B]
[B][COLOR=blue][SIZE=3][FONT=Times New Roman]Dim Biasi70854Query As String[/FONT][/SIZE][/COLOR][/B]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Set DB = CurrentDb[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Set FS = CreateObject("Scripting.FileSystemObject")[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Set rst = DB.OpenRecordset("[B][COLOR=blue]qrytblBiasi70854Process_01Images[/COLOR][/B]")[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman][B][COLOR=blue]Biasi70854Query[/COLOR][/B] = DCount("*", "[B][COLOR=blue]qrytblBiasi70854Process_01Images[/COLOR][/B]")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman][B][COLOR=blue]If Biasi70854Query[/COLOR][/B] > 0 Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Do While Not rst.EOF[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] If Not rst.EOF Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Title = rst![strTitle][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Initials = rst![strInitials][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Surname = rst![strSurname][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] VerifiedDate = rst![CurDate][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Customer = Title & " " & Initials & " " & Surname & "_" & VerifiedDate[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] ImageLoc = rst![ImagePath][/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] TopFolder = Mid(ImageLoc, 4, 27)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] TifFilePath = "J:\" & TopFolder[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] If Not FS.FolderExists(TifFilePath) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] MsgBox "Folder Doesn't Exist", , "Reading Tif Files"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] Set Folder = FS.GetFolder(TifFilePath)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] For Each File In Folder.Files[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] [B][COLOR=red]NameOfFile = GetAttr("File.Name")[/COLOR][/B][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] strTemp = Mid$(File.Name, InStrRev(File.Name, "\") + 1)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] FileLoc = Folder & "\" & File.Name[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman] If FileLoc = ImageLoc Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] FS.CopyFile Folder & "\" & strTemp, "[B][COLOR=blue]H:\BiasiImages" & "\" & Customer[/COLOR][/B] & ".tif"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] DoEvents[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] DoCmd.Echo True, "Copying File to New Loc: " & Folder & "\" & strTemp & "To :" & "[B][COLOR=blue]H:\BaisiImages" & "\" & Customer [/COLOR][/B]& ".tif"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Next[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] Loop[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]End If[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman][B][COLOR=blue]BiasiQuery[/COLOR][/B] = 0[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]rst.Close[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Set rst = Nothing[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Set DB = Nothing[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]DoCmd.Echo True, "Biais 70854 Process Complete"[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]End Function[/SIZE][/FONT]
The line in red is where this code keeps falling over, it's saying that it can't find the tif files although the files do exist, I've checked and double checked, I just stuck on trying to work out why this is, the only differences between this code structure and the first one above are shown in blue in this bit of code, so my thoughts are that this should work just like the other code, but not so far.
Hopefully someone can spot what may be wrong with the second code block.
Assistance/pointers would be most gratefully accepted.
Regards
John