Question : Sending email via button click not working

Hi experts,

Please see code below currently used.  Sometimes it works, sometimes it doesnt.  Works on some PCs and some it doesnt.  When it is not working it displays the error attached below as well.  I know this error means outlook does not recognize some or all of the recipients, but I am using the global address book for my company and those names do exist.  I am also open to using completely different code as long as it is not to complicated.  Thanks for any help!

Cody-
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
Private Sub cmdApprove_Click()

    Me.txtApprovedBy = CurrentUser()
    Me.txtApprovalDate = Now()

    Dim strEmail, strBody, strCCEmail As String
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem

    'Creates an Instance of Outlook
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)
    
    txtDate = Me.txtDate
    txtEID = Me.txtID
    txtPrinter = Me.cboPrinter
    txtEmpID = Me.cboEmpID
    txtEmpName = Me.txtEmpName
    txtReqNo = Me.txtReqNo
    txtTotalClicks = Me.txtTotalClicks
    txtJobID = Me.txtJobID
    txtJobName = Me.txtJobName
    txtPaperStock = Me.cboPaperStock
    txtReason = Me.txtReason
    txtAppBy = Me.txtApprovedBy
    txtAppDate = Me.txtApprovalDate
    txtEmail = Me.txtEmail
    

    'Create String with email address
    strEmail = "Docutek; " & txtEmail
    strBody = txtDate & Chr(13) & Chr(13)
    strBody = strBody & "The following discrepancy has been approved." & Chr(13) & Chr(13)
    strBody = strBody & "ID: " & txtEID & Chr(13)
    strBody = strBody & "Emp. ID: " & txtEmpID & Chr(13)
    strBody = strBody & "Employee Name: " & txtEmpName & Chr(13)
    strBody = strBody & "Printer: " & txtPrinter & Chr(13)
    strBody = strBody & "Req #: " & txtReqNo & Chr(13)
    strBody = strBody & "Total Clicks: " & txtTotalClicks & Chr(13)
    strBody = strBody & "Job ID: " & txtJobID & Chr(13)
    strBody = strBody & "Job Name: " & txtJobName & Chr(13)
    strBody = strBody & "Paper Stock: " & txtPaperStock & Chr(13)
    strBody = strBody & "Reason: " & txtReason & Chr(13)
    strBody = strBody & "Approved By: " & txtAppBy & Chr(13)
    strBody = strBody & "Approval Date: " & txtAppDate & Chr(13)
        
    'Creates and sends email
    With objEmail
        .To = strEmail
        .CC = "Vance, William; Marin, Sandra"
        .Subject = "Discrepancy Approved"
        .Body = strBody
        .Send
    End With

    Set objEmail = Nothing
    
    MsgBox "Discrepancy has been approved.", vbOKOnly + vbInformation, "Discrepancy Approved"
    DoCmd.Close acForm, "frmDiscrepancyApp"
    
    Exit Sub
End Sub

Answer : Sending email via button click not working

codyvance1,

The only thing left I can think of is to try to trap the name not being resolved, but that will require some research,
and I probably will not have a reply before tomorrow.

I suggest you click 'request attention', and in the request say that the Expert helping is recommending that we
send a "call for Experts" because he is running out of ideas :)

Patrick
Random Solutions  
 
programming4us programming4us