Good Morning all you brillant programmers out there! I would appreciate another pair of eyes on this Sub. The process emails a report to a list of email address from a table. The report iterates through the set in the table however when it finishes before closing out to the main Form it errors out with "wrong data type". The watch line is (DoCmd.SendObject acSendReport, "R Nursing Shift Report Data from Input", acFormatRTF, rs!email, , , "Nursing Shift Report", "Nursing Shift Report", False). Strange thing is it works flawlessly in a form from an earlier iteration of my same application.
Thank you for your time.
Private Sub cmdEmail_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Q Form Info from F Run Report", acViewNormal
DoCmd.OpenReport "R Nursing Shift Report Data from Input", acViewPreview, "", "", acNormal
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSave
DoCmd.Maximize
DoCmd.SetWarnings False
'Setup for email table iteration
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim strSQL As String
'Declare Report to be used for email
Dim stRpt As String
stRpt = "R Nursing Shift Report Data from Input"
'Iterate through all email addresses within the tblemail table to send the Nursing Shift Report
strSQL = "Select * from tblEmail"
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
rs.MoveFirst
Do While Not rs.EOF
DoCmd.SendObject acSendReport, "R Nursing Shift Report Data from Input", acFormatRTF, rs!email, , , "Nursing Shift Report", "Nursing Shift Report", False
DoCmd.SetWarnings False
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DoCmd.Close acReport, "R Nursing Shift Report Data from Input"
DoCmd.Close acQuery, "Q Form Info from F Run Report"
DoCmd.Close acForm, "F Run Report"
DoCmd.OpenForm "Main", acNormal, "", "", , acNormal
DoCmd.Maximize
End Sub
Thank you for your time.
Private Sub cmdEmail_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Q Form Info from F Run Report", acViewNormal
DoCmd.OpenReport "R Nursing Shift Report Data from Input", acViewPreview, "", "", acNormal
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSave
DoCmd.Maximize
DoCmd.SetWarnings False
'Setup for email table iteration
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim strSQL As String
'Declare Report to be used for email
Dim stRpt As String
stRpt = "R Nursing Shift Report Data from Input"
'Iterate through all email addresses within the tblemail table to send the Nursing Shift Report
strSQL = "Select * from tblEmail"
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
rs.MoveFirst
Do While Not rs.EOF
DoCmd.SendObject acSendReport, "R Nursing Shift Report Data from Input", acFormatRTF, rs!email, , , "Nursing Shift Report", "Nursing Shift Report", False
DoCmd.SetWarnings False
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DoCmd.Close acReport, "R Nursing Shift Report Data from Input"
DoCmd.Close acQuery, "Q Form Info from F Run Report"
DoCmd.Close acForm, "F Run Report"
DoCmd.OpenForm "Main", acNormal, "", "", , acNormal
DoCmd.Maximize
End Sub