Hi Moke123, i love this idea to prevent having to use IF, End IF or Select Case FileQty
I am getting an error when testing this, there is also an Integer set to ic, this is copying the files to a backup folder (accPath) before attaching then deleting
Do I have the code in the incorrect place or do I have this wrong all together ??
I am getting runtime error 53 File Not Found ?
I have commented out my select case file qty code to add much shorter one in of your suggestion of a loop of files to attach but the file not found error comes up!
are you able to correct my code and highlight corrected ?
I want to copy these files to AccPath then attach them to mail then delete them from imgPath, deleting from imgPAth works ok
Code:
Set fso =CreateObject("Scripting.FileSystemObject")
Set ObjFiles = fso.getfolder(imgPath).Files
FileQty = ObjFiles.Count
'Select Case FileQty
'Case 1
'f1 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-1" & ".jpg"
'FileCopy imgPath & f1, AccPath & f1
'Case 2
'f1 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-1" & ".jpg"
'f2 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-2" & ".jpg"
'FileCopy imgPath & f1, AccPath & f1
'FileCopy imgPath & f2, AccPath & f2
'Case 3
'f1 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-1" & ".jpg"
'f2 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-2" & ".jpg"
'f3 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-3" & ".jpg"
'FileCopy imgPath & f1, AccPath & f1
'FileCopy imgPath & f2, AccPath & f2
'FileCopy imgPath & f3, AccPath & f3
'Case 4
'f1 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-1" & ".jpg"
'f2 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-2" & ".jpg"
'f3 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-3" & ".jpg"
'f4 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-4" & ".jpg"
'FileCopy imgPath & f1, AccPath & f1
'FileCopy imgPath & f2, AccPath & f2
'FileCopy imgPath & f3, AccPath & f3
'FileCopy imgPath & f4, AccPath & f4
'Case 5
'f1 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-1" & ".jpg"
'f2 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-2" & ".jpg"
'f3 = Me.cboDealerIndex7 & "-" & Format(Now(),"dd-mm-yy") & "-3" & ".jpg"
'f4 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-4" & ".jpg"
'f5 = Me.cboDealerIndex7 & "-" &Format(Now(), "dd-mm-yy") & "-5" & ".jpg"
'FileCopy imgPath & f1, AccPath & f1
'FileCopy imgPath & f2, AccPath & f2
'FileCopy imgPath & f3, AccPath & f3
'FileCopy imgPath & f4, AccPath & f4
'FileCopy imgPath & f5, AccPath & f5
'End Select
For ic = 1 To FileQty
FileCopy imgPath & ic, AccPath & ic
Next ic
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = MailTo
.CC = mCC
For i = 1 To FileQty
.Attachments.Add imgPath & i
Next i
'Select Case FileQty
'Case 1
'.Attachments.Add imgPath & f1
'Case 2
'.Attachments.Add imgPath & f1
'.Attachments.Add imgPath & f2
'Case 3
'.Attachments.Add imgPath & f1
'.Attachments.Add imgPath & f2
'.Attachments.Add imgPath & f3
'Case 4
'.Attachments.Add imgPath & f1
'.Attachments.Add imgPath & f2
'.Attachments.Add imgPath & f3
'.Attachments.Add imgPath & f4
'Case 5
'.Attachments.Add imgPath & f1
'.Attachments.Add imgPath & f2
'.Attachments.Add imgPath & f3
'.Attachments.Add imgPath & f4
'.Attachments.Add imgPath & f5
'End Select
.subject = "Consignment" &" " & Me.txtConsignment
.Body = TOD & " " &"Your consignment" & " " & Me.txtConsignment &" " & "is now ready for collection," & Chr(10)& Chr(10) & _
"Total Boxes:" & "" & Me.txtTotalBoxes & Chr(10) & Chr(10) & _
"Package Information:" &" " & Me.cboPallets & "x" & " " &Me.cboPalletType & Chr(10) & Chr(10) & _
"Please ask your courier toquote consignment:" & " " & "C-" &Me.txtConsignment & " " & "upon collection" &Chr(10) & Chr(10) & _
"Estimated Total Weight:"& " " & Me.txtTotalWeight & " " &"Kg's" & Chr(10) & Chr(10) & _
"To help prevent delays, pleaseinform us or ask your courier to contact us with the anticipated collectionday:" & Chr(10) & Chr(10) & _
"Consignment details are:"& Chr(10) & Chr(10) & _
mBody & Chr(10) & Chr(10) & _
stSender
.Display
End With
Kill imgPath & "*.*"