I am trying to get this VBA code to work, which allows you to email from Access.
I am getting a 'Data type mismatch in criteria expression'.
I can't see anything that looks wrong to me, but I am not very experienced.
Here is the Code:
This is the Email table structure:Code:Private Sub btn_Send_Click() On Error GoTo Err_btn_Send_Click Dim stWhere As String '-- Criteria for DLookup Dim varTo As Variant '-- Address for SendObject Dim Message As String '-- E-mail text Dim DateSent As Variant '-- Sent date for e-mail text Dim Subject As String '-- Subject line of e-mail Dim EID As String '-- The ticket ID from form Dim stWho As String '-- Reference to Email_ADDR Dim From As String '-- Person who sent the email Dim strSQL As String '-- Create SQL update statement Dim errLoop As Error '-- Combo of names to assign ticket to stWho = Me.cboTo_Key stWhere = "Email_ADDR.ID = " & "'" & stWho & "'" '-- Looks up email address from Email_ADDR varTo = DLookup("[Email]", "Email_ADDR", stWhere) stSubject = "Subject" 'EID = Format(Me.EID, "00000") stText = Me.Message 'Write the e-mail content for sending to assignee DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1 'Set the update statement to disable command button 'once e-mail is sent strSQL = "UPDATE Email " & _ "SET Email.Sent = -1 " & _ "Where Email.EID = " & Me.EID & ";" On Error GoTo Err_Execute CurrentDb.Execute strSQL, dbFailOnError On Error GoTo 0 'Requery checkbox to show checked 'after update statement has ran 'and disable send mail command button Me.Sent.Requery Me.Sent.SetFocus Me.btn_Send.Enabled = False Exit Sub Err_Execute: ' Notify user of any errors that result from ' executing the query. If DBEngine.Errors.Count > 0 Then For Each errLoop In DBEngine.Errors MsgBox "Error number: " & errLoop.Number & vbCr & _ errLoop.Description Next errLoop End If Resume Next Exit_btn_Send_Click: Exit Sub Err_btn_Send_Click: MsgBox Err.Description Resume Exit_btn_Send_Click End Sub
EID: Autonumber
Subject: Short Text
Message: Short Text
Date Sent: Date/Time
To Key: Number
Sent: Yes/No
The SQL query looks OK to me, but perhaps I am missing something!




Reply With Quote
