Code below causes “Object Required” message when from from form button. I suspect that the DIM / SET commands are incorrect.
Object of code is to read a query and send an individual report based on each row of query. I want to loop until EOF is found in query. DO commands were pasted from converted macro to VB
Private Sub Command367_Click()
On Error GoTo Err_Command367_Click
Dim email As Recordset
Set email = db.openrecordset(“select-for-email”, dbopendynaset)
DoCmd.OpenQuery “select-for-email”, acNormal, acEdit
DoCmd.GoToRecord acQuery, “select-for-email”, acFirst
Do While Not email.EOF
DoCmd.GoToControl “lineid”
DoCmd.RunCommand acCmdCopy
SendKeys “^v”, False
SendKeys “{enter}”, False
DoCmd.SendObject acReport, “report-for-email”, “RichTextFormat(*.rtf)”, “chriss”, “”, “”, “Traveler”, “”, False, “”
DoCmd.GoToRecord acQuery, “select-for-email”, acNext
Loop
email.Close
Set email = Nothing
Exit_Command367_Click:
Exit Sub
Err_Command367_Click:
MsgBox Err.Description
Resume Exit_Command367_Click
End Sub