The majority of this code is fine, I'm trying to add a count to it so, in the email I can show how many attachments there are.
Here are the lines I have added myself:
Code:
[Dim loopcnt As Variant
Set loopcnt = "0"
loopcnt = loopcnt + 1
This line causes error: compile error: object required.
Full code:
Code:
Private Sub Command32_Click()
Dim rst As DAO.Recordset
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim strPath As String
Dim strFile As String
Dim loopcnt As Variant
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set rst = Me.RecordsetClone
Set loopcnt = "0"
rst.MoveLast
rst.MoveFirst
Do Until rst.EOF
strPath = "\\ramptecserver\finance\invoices\" & Company_Name & "" & rst!Order_Number & ""
strFile = rst!Order_Number & "-" & rst!Order_ID & "-" & rst!On_Issue & ".pdf"
Debug.Print strPath
Debug.Print strFile
If strFile <> "" Then
loopcnt = loopcnt + 1
With MailOutLook
.BodyFormat = olFormatRichText
.To = "bob@builder.com" '<<-- all emails go to same email address???
''.cc = ""
''.bcc = ""
.Subject = "text here" & loopcnt
.HTMLBody = "text here"
.Attachments.Add (strPath & strFile)
'.Send
.Display 'Used during testing without sending (Comment out .Send if using this line)
End With
End If
rst.MoveNext
Loop
'close recordset and clean up
rst.Close
Set rst = Nothing
Set appOutLook = Nothing
Set MailOutLook = Nothing
MsgBox "Done"
End Sub
When this is counting as I want I can hopefully update the subject line in the email with how many attachments there are. Also I would like to limit the maximum number of attachments. So, lets say 10 is the maximum before it makes a new email and starts again until the record set is complete. Ill have a lot of reading up to do on this but all help appreciated.
Thanks.