Trying to email a report from a form - based on a query that contains EmpID, Name, Email Address. I continue to get the error: "Data Type Mismatch in Criteria Expression". I am using the same format that I have used on other DB programs successfully except that this only has the EmpID to use for criteria without any other type of ID #. I have checked and rechecked my queries and forms but cannot see where the problem is. Below is the SQL for the query that feeds the report and also the event code used for my email button. I am wondering if someone could take a look at them and perhaps see something that I am not.
Report query:
SELECT tbl_Membership.EmpID, tbl_Membership.Name, tbl_results.ResultID, tbl_results.Date, tbl_results.Weight, tbl_results.WeightCal, tbl_results.Height, tbl_results.HeightCal, tbl_results.LastWkBMI, tbl_results.CurrWkBMI, tbl_results.BMIDiff, tbl_results.BMIPoints, tbl_results.ExerciseDays, tbl_results.ExercPoints, tbl_results.PhysActvty, tbl_results.WeightMgmt, tbl_results.LunchLearn, tbl_results.HRA, tbl_results.Library, tbl_results.Volunteer, tbl_results.Water, tbl_results.WaterReq, tbl_results.Journal, tbl_results.WkPoints
FROM tbl_Membership INNER JOIN tbl_results ON tbl_Membership.EmpID = tbl_results.EmpID
WHERE (((tbl_Membership.EmpID)=[forms]![frm_Results].[EmpID]));
Event Code for Button:
Private Sub btnEmail_Click()
On Error GoTo Err_btnEmail_Click
Dim stWhere As String '-- Criteria for DLookup
Dim varTo As Variant '-- Address for SendObject
Dim stText As String '-- E-mail text
Dim RecDate As Variant '-- Rec date for e-mail text
Dim stSubject As String '-- Subject line of e-mail
Dim stWho As String '-- Reference to qryclientSvcs
Dim stDept As String '-- Department who assigned ticket
Dim stSuggestionID As String '-- Work Order Number
Dim stCorpDte As String '-- CorpRecv Date of Project
Dim stRequester As String '-- Person Requesting
Dim stCoordinator As String '-- Suggestion Coordinator
Dim stIdea As String '-- Name Given to Suggestion
Dim stAssigned As String '-- Person who worked it
Dim stClosedDate As String '-- Actual Comp Date
Dim stDocName As String '-- Work Order Status/completion Details
'This forces the record to be saved.
If Me.Dirty Then
Me.Dirty = False
End If
'-- Combo of names to assign price change to
stWho = Me.EmpID
stWhere = "qryClientServices.EmpID = " & "'" & stWho & "'"
'-- Looks up email addresses from qryClientServices
varTo = DLookup("[Email Address]", "qryClientServices", stWhere)
stSubject = ":: Weekly Wellness Report :: "
stOrderID = Format(Me.EmpID)
'-- Evaluators employee who assigns ticket
stDocName = "IndivWklyByIndiv"
'Write the e-mail content for sending to assignee
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, varTo, , , stSubject, True
stDocName = "IndivWklyByIndiv"
Exit_btnEmail_Click:
Exit Sub
Err_btnEmail_Click:
MsgBox Err.Description
Resume Exit_btnEmail_Click
End Sub
Report query:
SELECT tbl_Membership.EmpID, tbl_Membership.Name, tbl_results.ResultID, tbl_results.Date, tbl_results.Weight, tbl_results.WeightCal, tbl_results.Height, tbl_results.HeightCal, tbl_results.LastWkBMI, tbl_results.CurrWkBMI, tbl_results.BMIDiff, tbl_results.BMIPoints, tbl_results.ExerciseDays, tbl_results.ExercPoints, tbl_results.PhysActvty, tbl_results.WeightMgmt, tbl_results.LunchLearn, tbl_results.HRA, tbl_results.Library, tbl_results.Volunteer, tbl_results.Water, tbl_results.WaterReq, tbl_results.Journal, tbl_results.WkPoints
FROM tbl_Membership INNER JOIN tbl_results ON tbl_Membership.EmpID = tbl_results.EmpID
WHERE (((tbl_Membership.EmpID)=[forms]![frm_Results].[EmpID]));
Event Code for Button:
Private Sub btnEmail_Click()
On Error GoTo Err_btnEmail_Click
Dim stWhere As String '-- Criteria for DLookup
Dim varTo As Variant '-- Address for SendObject
Dim stText As String '-- E-mail text
Dim RecDate As Variant '-- Rec date for e-mail text
Dim stSubject As String '-- Subject line of e-mail
Dim stWho As String '-- Reference to qryclientSvcs
Dim stDept As String '-- Department who assigned ticket
Dim stSuggestionID As String '-- Work Order Number
Dim stCorpDte As String '-- CorpRecv Date of Project
Dim stRequester As String '-- Person Requesting
Dim stCoordinator As String '-- Suggestion Coordinator
Dim stIdea As String '-- Name Given to Suggestion
Dim stAssigned As String '-- Person who worked it
Dim stClosedDate As String '-- Actual Comp Date
Dim stDocName As String '-- Work Order Status/completion Details
'This forces the record to be saved.
If Me.Dirty Then
Me.Dirty = False
End If
'-- Combo of names to assign price change to
stWho = Me.EmpID
stWhere = "qryClientServices.EmpID = " & "'" & stWho & "'"
'-- Looks up email addresses from qryClientServices
varTo = DLookup("[Email Address]", "qryClientServices", stWhere)
stSubject = ":: Weekly Wellness Report :: "
stOrderID = Format(Me.EmpID)
'-- Evaluators employee who assigns ticket
stDocName = "IndivWklyByIndiv"
'Write the e-mail content for sending to assignee
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, varTo, , , stSubject, True
stDocName = "IndivWklyByIndiv"
Exit_btnEmail_Click:
Exit Sub
Err_btnEmail_Click:
MsgBox Err.Description
Resume Exit_btnEmail_Click
End Sub