What is wrong with my Code?!

smbarney

Registered User.
Local time
Today, 13:07
Joined
Jun 7, 2006
Messages
60
I am trying to send a report via email that is in the body of the email not an attachment. In addition, I only want the current record sent, and not the entire database. Every time I run it, however, I get an error message that says "An expression you entered is the wrong data type for one of the arguments" I know I am missing something, but I cannot see it. Can someone help? Thanks. Here is my code.

Private Sub Command350_Click()
On Error GoTo Err_Command350_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "IncidentReport"
strWhere = "[IntakeID]=" & Me!IntakeID
Me.Refresh
DoCmd.OutputTo acOutputReport, strDocName, acFormatHTML, "c:\myreport.html", , , strWhere


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.To = "Forms!IncidentForm!btEmail"
.Subject = "Incident Report"
.BodyFormat = olFormatHTML
.HTMLBody = "C:\myreport.html"
.Display
End With



Exit_Command350_Click:
Exit Sub

Err_Command350_Click:
MsgBox Err.Description
Resume Exit_Command350_Click

End Sub
 
You didn't say what line is causing the error, but this is definitely a problem:

.To = "Forms!IncidentForm!btEmail"

should be:

.To = Forms!IncidentForm.btEmail
 
Are the fields [IntakeID] on the report and Me![IntakeID] both numeric?

Comment out the code to just get the report to open within Access before emailing it to check it's not an error within the report filter.

Regards,
Pete
 

Users who are viewing this thread

Back
Top Bottom