Lotus Notes Automation Code
CutAndPaste,
Type mismatch is when you are trying to put one type of value into a place where Access is expecting a different type. For example, putting a string value into an integer field causes error 13, type mismatch. I would bet that this is the line causing the problem: Me!txtDisplayCompanyID = rst!txtCompanyID but I really don't know without seeing your form and your table. I would post my code, however I don't do it this way.
The docmd works well for one email; however, to send multiple emails (which I frequently do) I use lotus notes automation. I included my code below, hopefully you are able to use it with only minor Tweeking.
There are four subs/functions. The first one is unique to each email function and the other four are part of my "Mail Tools" module. I use these in every database and every email function I use.
I also attached a file with the functions (may be a little easier to read) .Reply if you are still having problems, or you can email me directly.
Have fun.
'*************************************
Option Compare Database
Option Explicit
Public mobjDB As Object
Public Sub SEND_EMAILS()
'open the session with the lotus notes server
'this sub will output a report as a file
'attach the file and add the predetermined subject and body
'delete the file that was output
'close the session with the server
If OPEN_SESSION Then
'output report to text file on C:\
DoCmd.OutputTo acOutputReport, "My Report", acFormatRTF, "C:\My File Name", False
'put your do loop here
'reference the email report sub to mail the file
If EMAIL_REPORT("JoeSmith@AOL.com", "My Email Body", "My Subject Line", "C:\My File Name") = True Then
MsgBox "Message Sent"
Else
'error in email module
End If
'end your loop here
'delete the file
Kill ("C:\My File Name")
'call the close session sub to destroy the objects
CLOSE_SESSION
Else
'session not opened properly
End If
End Sub
Public Function OPEN_SESSION() As Boolean
Dim objSession As Object
Dim strServer As String
Dim strMailFile As String
'lotus notes must be open for module to work correctly
If MsgBox("Do you have lotus notes running?", vbCritical + vbYesNo, "Warning!") = vbYes Then
'this code must be left out of the loop so that only one session is started
Set objSession = CreateObject("Notes.NOTESSESSION")
strServer = objSession.GETENVIRONMENTSTRING("mailserver", True)
strMailFile = objSession.GETENVIRONMENTSTRING("mailfile", True)
Set mobjDB = objSession.GETDATABASE(strServer, strMailFile)
OPEN_SESSION = True
Else
MsgBox "Please start Lotus Notes and try again.", vbOKOnly, "Emails"
OPEN_SESSION = False
End If
End Function
Public Function EMAIL_REPORT(strSendTo As String, strBody As String, strSubject As String, Optional strFile As String) As Boolean
On Error GoTo EmailReport_Err
Dim objDoc As Object
Dim objRichTextAttach As Object
Dim objRichTextItem As Object
Dim objAttachment As Object
Const NOTES_RECIPIENTS = ""
Const NOTES_REPORTS_ADMIN_USER = ""
Const NOTES_MAIL_FILE = "C:\Email.txt"
Set objDoc = mobjDB.CREATEDOCUMENT
Set objRichTextAttach = objDoc.CREATERICHTEXTITEM("File")
Set objRichTextItem = objDoc.CREATERICHTEXTITEM(objDoc, "Body")
If strFile <> "" Then
Set objAttachment = objRichTextAttach.EMBEDOBJECT(1454, "", strFile)
End If
'set up the email to be sent
objRichTextItem.AppendText strBody
objDoc.REPLACEITEMVALUE "SendTo", strSendTo
objDoc.REPLACEITEMVALUE "Subject", strSubject
objDoc.SaveMessageOnSend = True 'send E-mail
objDoc.SEND False 'false for do not attach a form
EMAIL_REPORT = True
Exit_Here:
Set objAttachment = Nothing
Set objDoc = Nothing
Set objRichTextAttach = Nothing
Set objRichTextItem = Nothing
Exit Function
EmailReport_Err:
EMAIL_REPORT = False
Resume Exit_Here
End Function
Public Sub CLOSE_SESSION()
Set mobjDB = Nothing
End Sub