TomDuCrosbie
Technical User
I have a command button I want to send the contents of a form, as a report. I've written this code to do it.
Private Sub ResultsOK_Click()
On Error GoTo Err_ResultsOK_Click
Dim qdef As QueryDef
Dim strSQL As String
Dim strParam As String
Set qdef = CurrentDb().QueryDefs("ReferralResultsMailReport"
strParam = Forms!frmReferralResults!txtReferralID
strSQL = "Exec ReferralResultsMailReport" & strParam
qdef.SQL = strSQL
Dim stDocName, strSubject, strSendTo, strCC, strBody As String
stDocName = "rptReferralResultsforMail"
stSubject = "Results of your Referral"
stSendTo = Me!ReferredBy
strCC = "Tom Petersen"
stBody = Me!txtFirstName & " " & Me!txtLastName
DoCmd.SendObject acReport, stDocName, acFormatRTF, stSendTo, , stCC, stSubject, stBody
The problem is, I get a runtime error "91" Object variable or with block variable not set. I get the error on this line
Set qdef = CurrentDb().QueryDefs("ReferralResultsMailReport"
What does this mean? THe database is a access front end with MS SQL server back end,and ReffealResultsMailReport is a stored procedure. I also have the DAO 3.6 object library attached.
Private Sub ResultsOK_Click()
On Error GoTo Err_ResultsOK_Click
Dim qdef As QueryDef
Dim strSQL As String
Dim strParam As String
Set qdef = CurrentDb().QueryDefs("ReferralResultsMailReport"
strParam = Forms!frmReferralResults!txtReferralID
strSQL = "Exec ReferralResultsMailReport" & strParam
qdef.SQL = strSQL
Dim stDocName, strSubject, strSendTo, strCC, strBody As String
stDocName = "rptReferralResultsforMail"
stSubject = "Results of your Referral"
stSendTo = Me!ReferredBy
strCC = "Tom Petersen"
stBody = Me!txtFirstName & " " & Me!txtLastName
DoCmd.SendObject acReport, stDocName, acFormatRTF, stSendTo, , stCC, stSubject, stBody
The problem is, I get a runtime error "91" Object variable or with block variable not set. I get the error on this line
Set qdef = CurrentDb().QueryDefs("ReferralResultsMailReport"
What does this mean? THe database is a access front end with MS SQL server back end,and ReffealResultsMailReport is a stored procedure. I also have the DAO 3.6 object library attached.