Problems Mailing a Form from via Outlook

DaveBre

New member
Local time
Today, 22:58
Joined
Aug 11, 2013
Messages
4
Hi Everyone,

I'm very new to access/vba, but I'm trying to utilise some code I've come across to email details in a form to an employee. I've taken the original code and tried to modify it for my own use (without much sucess).

When running the code below I get the error 'Data type mismatch in criteria expression'. I've done as much as I can to try and resolve the issue but my lack of experience is showing!

The database contains two tables tblpersonnel and tbloverpaments, both joined one to one with a primary key in the form of employeeID (both integers)

Any help to review the code would be appreciated.

Thanks

David

PS as I'm a new poster it doesn't seem to allow me to post the word e m a i l, so I've had to change each instance to e*ail.

Private Sub CmdNotify_Click()
On Error GoTo Err_cmdNotify_Click

Dim StWhere As String 'Criteria for DLookup
Dim Varto As Variant 'Address for SendObject
Dim stText As String 'E*ail Text
Dim stSubject As String 'Subject line of e*ail
Dim stWho As String 'Reference to tblPersonnel
Dim strSQL As String 'Create SQL statement to update
Dim errLoop As Error

'-- Combo of Employee Names
stWho = Me.cboEmpID
StWhere = "tblPersonnel.SAPID = " & "'" & stWho & "'"
'Looks up e*ail address from table
Varto = DLookup("[E*ail]", "tblPersonnel", StWhere)

stSubject = "::Test::"

stText = "Test"

'Write the e*ail contect for sending to employee
DoCmd.SendObject , , acFormatTXT, Varto, , , stSubject, stText, -1

On Error GoTo Err_Execute
CurrentDb.Execute strSQL, dbFailOnError
On Error GoTo 0

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_cmdNotify_Click:
Exit Sub

Err_cmdNotify_Click:
MsgBox Err.Description
Resume Exit_cmdNotify_Click

End Sub
 
On what line does it error out on?

StWhere = "tblPersonnel.SAPID = " & "'" & stWho & "'"

doesn't look correct. Try replacing it with

If SAPID is Text:

StWhere = "tblPersonnel.SAPID = '" & stWho & "'"

If SAPID is Numeric:

StWhere = "tblPersonnel.SAPID = " & stWho

Linq ;0)>
 
Missinglinq,

Thank you very much for posting the reply. I've changed the code and now the email generates, however the to email address is in the format of 'FIRSTNAME.SURNAME@COMPANY.COM#mailto:FIRST.SURNAME@COMPANY.COM#

Any idea what might be causing that?

Thanks again.

David
 
Not a clue, sorry! The Where part of this is pretty generic, but I've never done this sort of thing with Outlook. Hopefully someone who has will wander by and lend a hand!

Linq ;0)>
 
Thanks Missinglinq, I managed to resolve the issue. I originally had the email address as a hyperlink in one of the tables, then converted it to text. As a result the email address effectively ended up twice.

Thanks again.

Dave
 

Users who are viewing this thread

Back
Top Bottom