can you show the function?
Function AutoEmail(MySQL As String)
Dim objOutlook As Outlook.Application
Dim objEmailItem As MailItem
Dim rs As DAO.Recordset
Dim rssent As DAO.Recordset
Dim Reccount As Long
Dim i As Integer
Dim SID As String
Set rs = CurrentDb.OpenRecordset(MySQL)
'count the Records
Reccount = DCount("[stuid]", "QAutoSendEmail")
Forms!frm_login!lblSendingEmail.Visible = True
'*************
' if the user dose't have Email, move next
If Reccount > 0 Then
rs.MoveFirst
Do Until rs.EOF
For i = i + 1 To Reccount
If IsNull(rs!Email) Then
i = i - 1
Reccount = Reccount - 1
rs.MoveNext
Else
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
End If
' Display lbl Sending Email process
Forms!frm_login!lblSendingEmail.Caption = ("Sending " & i & " Out of " & Reccount & " " & rs!Email)
Set objEmailItem = objOutlook.CreateItem(olMailItem)
With objEmailItem
.To = rs!Email
.Subject = rs!corsname & " Certificate Will be Expired after 30 Days"
.Body = "Dear/ " & rs!stuname
.Display
' To fill out the sentdate field
Set rssent = CurrentDb.OpenRecordset("SELECT tbl_AtndCors.stuID, tbl_AtndCors.SentDate, tbl_Session.corsID " & _
" FROM tbl_Session INNER JOIN tbl_AtndCors ON tbl_Session.SessionID = tbl_AtndCors.SessionID WHERE tbl_AtndCors.stuID = " & rs!stuID & " And " & _
" tbl_Session.corsID = " & rs!corsID)
rssent.Edit
rssent!SentDate = Date
rssent.Update
End With
Set rssent = Nothing
Set objEmailItem = Nothing
Set objOutlook = Nothing
rs.MoveNext
End If
Next i
Loop
Else
End If
rs.Close
rssent.Close
End Function