send email on query

ihere

New member
Local time
Today, 03:52
Joined
May 11, 2014
Messages
5
I need to send email based on query (specific record) to specific one
I have erorr " object required " and " Object variable or with block variable not set" I do not know what is the problem
please some help
thanks



code here


Option Compare Database
Private Sub Command0_Click()
Dim mydb As DAO.Database
Dim rst As DAO.Recordset
Dim tempst As String
Dim qdf As QueryDef
Dim rest As String
Dim rst2 As Recordset
Dim mdatee As Date
Dim mpayroll As String
Dim mto As String
Set mydb = CurrentDb
tempst = "SELECT DISTINCT payroll, datee, email FROM payed query WHERE datee = '" & dodo & "'" & " ORDER BY payroll"
Set rst = mdb.OpenRecordset(tempst, dbOpenDynaset)
rst.MoveFirst
While Not rst.EOF
mpayroll = rst("payroll")
mdatee = rst("datee")
Set qdf = mydb.QueryDefs("payedQuery")
rest = "SELECT payed.payroll,personal.namee,payed.type,payed.amount,personal.email,payed.datee" & _
"FROM payed inner join personal on payed.payroll = personal.payroll" & _
"WHERE payed.payroll= mpayroll, payed.datee = mdatee " & _
"ORDER BY payed.payroll"
qdf.SQL = rest
qdf.Close
Set rst2 = qdf.OpenRecordset
rst2.MoveFirst
'While Not rst2.EOF
mto = rst2("email")
DoCmd.SendObject acSendQuery, payedQuery, acFormatXLS, mto, , , "ÞíãÉ ÇáÚáÇÌ ÇáÇÓÑí æÇáÔÎÕí ", "ÞíãÉ ÝæÇÊíÑ ÇáÚáÇÌ ÇáÔÎÕí æÇáÇÓÑí ÇáÊì ÎÑÌÊ ãä ÇáØÈíÉ", False
rst2.Close
rst2.MoveNext
Wend
mdb.Close
End Sub
 
This would appear to be that problem:

qdf.Close
Set rst2 = qdf.OpenRecordset

It's not the last one you'll run into. ;)
 

Users who are viewing this thread

Back
Top Bottom