Here's everything as it is stands:
Sub EmailData()
Dim tbDataToBeEmailed As ADODB.Recordset
Dim tbUser As ADODB.Recordset
Dim qHoursIDNameEmail As ADODB.Recordset
Dim tbDataToBeEmailedIndividual As ADODB.Recordset
Dim nameCount As Integer
Dim totalNameCount As Integer
Dim i As Integer
Dim DisplayMsg As Boolean
Dim Counter As Long
Dim tbLinks As ADODB.Recordset
Dim FirstDate As Date
Dim LastDate As Date
Set cnCurrent = CurrentProject.Connection
Set tbDataToBeEmailed = New ADODB.Recordset
Set tbUser = New ADODB.Recordset
Set tbLinks = New ADODB.Recordset
Set qHoursIDNameEmail = New ADODB.Recordset
Set tbDataToBeEmailedIndividual = New ADODB.Recordset
DisplayMsg = True
nameCount = 1
tbUser.Open "tbUser", cnCurrent, adOpenKeyset, adLockOptimistic,
adCmdTable
tbDataToBeEmailed.Open "tbDataToBeEmailed", cnCurrent, adOpenKeyset,
adLockOptimistic, adCmdTable
qHoursIDNameEmail.Open "qHoursIDNameEmail", cnCurrent, adOpenKeyset,
adLockOptimistic, adCmdTable
tbDataToBeEmailedIndividual.Open "tbDataToBeEmailedIndividual", cnCurrent,
adOpenKeyset, adLockOptimistic, adCmdTable
tbLinks.Open "tbLinks", cnCurrent, adOpenKeyset, adLockOptimistic,
adCmdTable
RetValue = MsgBox("Do you want to send out the incomplete ACIS hours to
all
required users?", vbYesNo)
If RetValue = vbNo Then Exit Sub
'Delete data from tables
cnCurrent.Execute "DELETE * from tbUser"
cnCurrent.Execute "DELETE * from tbDataToBeEmailed"
cnCurrent.Execute "DELETE * from tbDataToBeEmailedIndividual"
'Build dataset of employees to be emailed
cnCurrent.Execute "INSERT INTO tbDataToBeEmailed ( [Clock No], [First
Name],
Surname, Email, error_date, missing_hour ) " & _
"SELECT tbEmployees.[Clock No], tbEmployees.[First Name],
tbEmployees.Surname, tbEmployees.Email, " & _
"tbExceptionReport.error_date,
tbExceptionReport.missing_hour " & _
"FROM tbEmployees INNER JOIN tbExceptionReport ON
tbEmployees.[Clock No] = tbExceptionReport.auth_id " & _
"WHERE (((tbExceptionReport.DoNotEmail) = False)) " & _
"ORDER BY tbEmployees.[Clock No],
tbExceptionReport.error_date"
'Move to the first record of qHoursIDNameEmail
qHoursIDNameEmail.MoveFirst
For i = 1 To qHoursIDNameEmail.RecordCount
'Loop while not at the last record
While Not qHoursIDNameEmail.EOF
'Assign value to variable
totalNameCount = qHoursIDNameEmail.RecordCount
'Append the ID for only the one user in tbUser
tbUser.AddNew
tbUser!ClockNo.Value = qHoursIDNameEmail![Clock No].Value
tbUser!Email.Value = qHoursIDNameEmail!Email.Value
tbUser!firstname.Value = qHoursIDNameEmail![First Name].Value
tbUser.Update
'Append the data relating to this user
cnCurrent.Execute "qAppDataToBeEmailedIndividual", dbFailOnError
'Populate the from and to date variables
tbDataToBeEmailedIndividual.MoveFirst
FirstDate = tbDataToBeEmailedIndividual!error_date.Value
tbDataToBeEmailedIndividual.MoveLast
LastDate = tbDataToBeEmailedIndividual!error_date.Value
'Cancel email message
On Error GoTo errCancelEmail
'Can send email with no attachment, detailing the from and to dates
Call NotesMailSend(tbUser!Email.Value, "ACIS Time Recording", "*** THIS
IS AN AUTOMATED EMAIL SENT ON BEHALF OF DSI AND WILLIAM BUCK CONSULTING
(VIC)
PTY LTD ***" & vbNewLine & vbNewLine & _
"Dear " & tbUser!firstname.Value & vbNewLine &
vbNewLine & _
"You have not entered time into the ACIS
time-recording system on some dates between " & FirstDate & " to " &
LastDate
& ". " & _
"It would be greatly appreciated if you could
complete all outstanding timesheet data entries " & _
"by " & tbLinks!ReturnByDate.Value & " in order
that these hours can be included in DSI's ACIS return." & vbNewLine &
vbNewLine & _
"ACIS revenue is very important to DSI and your
cooperation would be very much appreciated. If you are " & _
"experiencing difficulties using the ACIS
system, please let us know by return email (please include " & _
"your telephone number) and we will endeavour
to
provide you with follow-up assistance." & vbNewLine & vbNewLine & _
"If you would like to better understand ACIS,
please contact Brian O'Meara via email " & _
"(Brian.O'(e-mail address removed)) to
arrange additional training." & vbNewLine & vbNewLine & _
"Your support of DSI is greatly appreciated.")
'This allows an attachment but will not send automatically
'DoCmd.SendObject acTable, "tbDataToBeEmailedIndividual", acFormatXLS,
tbUser!Email.Value, , , "ACIS Time Recording", _
"*** THIS IS AN AUTOMATED EMAIL SENT ON BEHALF
OF DSI AND WILLIAM BUCK CONSULTING (VIC) PTY LTD ***" & vbNewLine &
vbNewLine
& _
"Dear " & tbUser!firstname.Value & vbNewLine &
vbNewLine & _
"Please find attached a listing of the dates on
which you have not entered time into the ACIS time-recording " & _
"system. It would be greatly appreciated if you
could complete all outstanding timesheet data entries " & _
"by " & tbLinks!ReturnByDate.Value & " in order
that these hours can be included in DSI's ACIS return." & vbNewLine &
vbNewLine & _
"ACIS revenue is very important to DSI and your
cooperation would be very much appreciated. If you are " & _
"experiencing difficulties using the ACIS
system, please let us know by return email (please include " & _
"your telephone number) and we will endeavour
to
provide you with follow-up assistance." & vbNewLine & vbNewLine & _
"If you would like to better understand ACIS,
please contact Brian O'Meara via email " & _
"(Brian.O'(e-mail address removed)) to
arrange additional training." & vbNewLine & vbNewLine & _
"Your support of DSI is greatly appreciated." &
vbNewLine & vbNewLine & _
"Kind regards,", True
cnCurrent.Execute "DELETE * from tbUser"
cnCurrent.Execute "DELETE * from tbDataToBeEmailedIndividual"
qHoursIDNameEmail.MoveNext
nameCount = nameCount + 1
i = i + 1
Wend
Next
tbUser.Close
tbDataToBeEmailed.Close
tbDataToBeEmailedIndividual.Close
qHoursIDNameEmail.Close
Set tbUser = Nothing
Set tbDataToBeEmailed = Nothing
Set tbDataToBeEmailedIndividual = Nothing
Set qHoursIDNameEmail = Nothing
Exit Sub
errCancelEmail:
Dim ErrorNumber
ErrorNumber = Err.Number
Select Case ErrorNumber
Case 287
MsgBox "Send email cancelled by user", vbOKOnly
Case 2501
MsgBox "Send email cancelled by user", vbOKOnly
Case 2295
MsgBox "Unknown recipient - process stopped", vbOKOnly
Case 3265
MsgBox "Invalid email name - Process stopped", vbOKOnly
Case Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly
End Select
End Sub
Douglas J. Steele said:
I believe Duane's trying to figure out what tbDataToBeEmailedIndividual
is.
If it's a recordset, where are you opening it? How you opened it is
important in terms of knowing whether it's going to see changes.