I'm a newbie to coding and am having a problem with code that was given to me to modify for my particular use. My goal is to email a particular page of a report based upon an ID (Named SPID). I have the report created and underlying queries and it works fine. Now the problem... I was given sample code of how to do this but when I modify for my use I get the following error: "Run-time error '13' - Type Mismatch." While I think I know what a type mismatch is, I can't find any reason for it in the code. My code is below. If anyone can set me straight on what is going on, I would greatly appreciate. BTW, all variables in the queries are string variables. The highlighted line in debugger is:Set RstTmp = db.OpenRecordset(SqlStr, dbOpenSnapshot)
Private Sub cmdEmail_Click()
Dim db As Database
Dim RstTmp As Recordset
Dim Loop1 As Long
Dim SqlStr As String
Set db = CurrentDb()
SqlStr = "SELECT qryMerged.CustomerID, qryMerged.SPID, qryMerged.EmailTest, qryMerged.Customer, qryMerged.Type, qryMerged.CustCity, qryMerged.CustSt FROM qryMerged GROUP BY qryMerged.CustomerID, qryMerged.SPID, qryMerged.EmailTest, qryMerged.InstallDate, qryMerged.CustSt;"
Set RstTmp = db.OpenRecordset(SqlStr, dbOpenSnapshot)
DoEvents
On Error Resume Next
RstTmp.MoveLast
RstTmp.MoveFirst
On Error GoTo 0
If RstTmp.RecordCount = 0 Then
MsgBox "There are no events"
Exit Sub
End If
For Loop1 = 1 To RstTmp.RecordCount
Me!txtBox.Value -RstTmp!SPID
DoCmd.SendObject acSendReport, "rptWorksheetRental", acFormatRTF, _
RstTmp!SPID, , , "Test Subject", "Test Message", False
RstTmp.MoveNext
Next Loop1
MsgBox (Loop1 - 1) & " Messages sent"
db.Close
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub
Private Sub cmdEmail_Click()
Dim db As Database
Dim RstTmp As Recordset
Dim Loop1 As Long
Dim SqlStr As String
Set db = CurrentDb()
SqlStr = "SELECT qryMerged.CustomerID, qryMerged.SPID, qryMerged.EmailTest, qryMerged.Customer, qryMerged.Type, qryMerged.CustCity, qryMerged.CustSt FROM qryMerged GROUP BY qryMerged.CustomerID, qryMerged.SPID, qryMerged.EmailTest, qryMerged.InstallDate, qryMerged.CustSt;"
Set RstTmp = db.OpenRecordset(SqlStr, dbOpenSnapshot)
DoEvents
On Error Resume Next
RstTmp.MoveLast
RstTmp.MoveFirst
On Error GoTo 0
If RstTmp.RecordCount = 0 Then
MsgBox "There are no events"
Exit Sub
End If
For Loop1 = 1 To RstTmp.RecordCount
Me!txtBox.Value -RstTmp!SPID
DoCmd.SendObject acSendReport, "rptWorksheetRental", acFormatRTF, _
RstTmp!SPID, , , "Test Subject", "Test Message", False
RstTmp.MoveNext
Next Loop1
MsgBox (Loop1 - 1) & " Messages sent"
db.Close
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub