Hi Guy's I thought I had this one, I have been playing around with code for backing up 3 folders aPath is always "from folder" and bPath is always to folder, it's coming up debug object variable or With block variable not set run time error 91
The reason I have played about with it is that if there are no files to backup, then it needs to abort Name As option, I think I just have a sequence wrong somewhere, the debug is aFiles = Dir(aPath & "*.*")
Can this code be corrected please ?
Code:
Dim aPath As String, bPath As String
Dim aCount As Integer, bCount As Integer, MyInput As Integer
Dim aFSO As Object, bFSO As Object
Dim aFiles As Object, bFiles As Object
If Me.cboFolderActions = "Backup PO's" Then
MyInput = InputBox("Select Which Folder To Backup?" & vbNewLine & _
" > 1 < = In Stock" & vbNewLine & _
" > 2 < = Due In" & vbNewLine & _
" > 3 < = On Hold", "WHICHFOLDER")
Select Case MyInput
Case 1
aPath = "T:\Local\HG PO's\In Stock\"
bPath = "T:\Customer\Customer Backup\HG's\InStock\"
aFiles = Dir(aPath & "*.*")
Set aFSO =CreateObject("Scripting.FileSystemObject")
Set bFSO = CreateObject("Scripting.FileSystemObject")
Set aFiles = aFSO.getfolder(aPath).Files
Set bFiles = bFSO.getfolder(bPath).Files
aCount = aFiles.Count
bCount = bFiles.Count
If MsgBox("In Folder:" & vbNewLine & _
aPath & "(HG STOCK)" & vbNewLine & _
"There Are: " & aCount & " "& "PO's To Back Up" & vbNewLine & vbNewLine & _
"In Backup Folder:" & vbNewLine & _
bPath & "(CUSTOMER BACKUP)" & vbNewLine& _
"There Are: " & bCount & " "& "PO's Already Backed Up", vbInformation + vbOKOnly, "FILESCONFIRMED") = vbOK Then
If aFiles = vbNullString Then
MsgBox ("Aborting Backup as there is no files tobackup!"), vbInformation + vbOKOnly, "NO FILES TO BACKUP"
DoCmd.CancelEvent
Else
Do Until aFiles = vbNullString
Name aPath & aFiles As bPath & aFiles
aFiles = Dir
Loop
End If
End If
Set aFSO = Nothing
Set bFSO = Nothing
Set aFiles = Nothing
Set bFiles = Nothing
Case 2
aPath = "T:\Local\HG PO's\Due In\"
bPath = "T:\Customer\Customer Backup\HG's\DueIn\"
aFiles = Dir(aPath & "*.*")
Set aFSO = CreateObject("Scripting.FileSystemObject")
Set bFSO =CreateObject("Scripting.FileSystemObject")
Set aFiles = aFSO.getfolder(aPath).Files
Set bFiles = bFSO.getfolder(bPath).Files
aCount = aFiles.Count
bCount = bFiles.Count
If MsgBox("In Folder:" & vbNewLine & _
aPath & "(DUE IN)" & vbNewLine & _
"There Are: " & aCount & " "& "PO's To Back Up" & vbNewLine & vbNewLine & _
"In Backup Folder:" & vbNewLine & _
bPath & "(CUSTOMER BACKUP)" & vbNewLine& _
"There Are: " & bCount & " "& "PO's Already Backed Up", vbInformation + vbOKOnly, "FILESCONFIRMED") = vbOK Then
If aFiles = vbNullString Then
MsgBox ("Aborting Backup as there is no files tobackup!"), vbInformation + vbOKOnly, "NO FILES TO BACKUP"
DoCmd.CancelEvent
Else
Do Until aFiles = vbNullString
Name aPath & aFiles As bPath & aFiles
aFiles = Dir
Loop
End If
End If
Set aFSO = Nothing
Set bFSO = Nothing
Set aFiles = Nothing
Set bFiles = Nothing
Case 3
aPath = "T:\Local\HG PO's\On Hold\"
bPath = "T:\Customer\Customer Backup\HG's\OnHold\"
aFiles = Dir(aPath & "*.*")
Set aFSO =CreateObject("Scripting.FileSystemObject")
Set bFSO =CreateObject("Scripting.FileSystemObject")
Set aFiles = aFSO.getfolder(ePath).Files
Set bFiles = bFSO.getfolder(fPath).Files
aCount = aFiles.Count
bCount = bFiles.Count
If MsgBox("In Folder:" & vbNewLine & _
aPath & "(ON HOLD)" & vbNewLine & _
"There Are: " & aCount & " "& "PO's To Back Up" & vbNewLine & vbNewLine & _
"In Backup Folder:" & vbNewLine & _
bPath & "(CUSTOMER BACKUP)" & vbNewLine& _
"There Are: " & bCount & " "& "PO's Already Backed Up", vbInformation + vbOKOnly, "FILESCONFIRMED") = vbOK Then
If aFiles = vbNullString Then
MsgBox ("Aborting Backup as there is no files tobackup!"), vbInformation + vbOKOnly, "NO FILES TO BACKUP"
DoCmd.CancelEvent
Else
Do Until aFiles = vbNullString
Name aPath & aFiles As bPath & aFiles
aFiles = Dir
Loop
End If
End If
Set aFSO = Nothing
Set bFSO = Nothing
Set aFiles = Nothing
Set bFiles = Nothing
End Select
End If