chainedtodesk
Programmer
i have the below code set up but i keep getting an "Argument Not Optional" when i try to execute it. and it always points to the statement "SendCustList (rst1!addr)" i have this running without the attachment piece, but in trying to add that part it wont go, any ideas????? thanks
Option Compare Database
Option Explicit
Function sender() As Boolean
Dim dbs As DAO.Database
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim sql1 As Variant
Dim sql2 As Variant
Set dbs = CurrentDb
sql1 = "Select addr from tblEmail"
Set rst1 = dbs.OpenRecordset(sql1)
sql2 = "Select atch from tblEmail"
Set rst2 = dbs.OpenRecordset(sql2)
Do Until rst1.EOF
SendCustList (rst1!addr) <- ERRORS HERE
SendCustList (rst2!atch)
rst1.MoveNext
rst2.MoveNext
Loop
rst1.Close
rst2.Close
dbs.Close
End Function
Function SendCustList(addr As String, atch As String) As Boolean
Dim objoutlook As Object
Dim objitem As MailItem
Set objoutlook = CreateObject("Outlook.Application")
' Create olMailItem
Set objitem = objoutlook.CreateItem(olMailItem)
With objitem
.Subject = "weekly sales flyer."
.To = addr
'.CC = "xxx@xxx.xxx"
'.BCC = "xxx@xxx.xxx"
.Body = "weekly sales flyer."
.Attachments.Add atch
.send
End With
Set objitem = Nothing
Set objoutlook = Nothing
End Function
Option Compare Database
Option Explicit
Function sender() As Boolean
Dim dbs As DAO.Database
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim sql1 As Variant
Dim sql2 As Variant
Set dbs = CurrentDb
sql1 = "Select addr from tblEmail"
Set rst1 = dbs.OpenRecordset(sql1)
sql2 = "Select atch from tblEmail"
Set rst2 = dbs.OpenRecordset(sql2)
Do Until rst1.EOF
SendCustList (rst1!addr) <- ERRORS HERE
SendCustList (rst2!atch)
rst1.MoveNext
rst2.MoveNext
Loop
rst1.Close
rst2.Close
dbs.Close
End Function
Function SendCustList(addr As String, atch As String) As Boolean
Dim objoutlook As Object
Dim objitem As MailItem
Set objoutlook = CreateObject("Outlook.Application")
' Create olMailItem
Set objitem = objoutlook.CreateItem(olMailItem)
With objitem
.Subject = "weekly sales flyer."
.To = addr
'.CC = "xxx@xxx.xxx"
'.BCC = "xxx@xxx.xxx"
.Body = "weekly sales flyer."
.Attachments.Add atch
.send
End With
Set objitem = Nothing
Set objoutlook = Nothing
End Function