0

MS Access 2019 form supplies data to send an email via Outlook 2019. The recipient (email address) will not populate the email "To" box unless it is text, but will not if it is an email. When 'proving the VBA data transfer via msgbox, it will. I suspect it could be my dim declaration type but I have tried others such as string and variant(illustrated) The code below will allow the MsgBox to run, but nothing else. My form fields are named" 'Name' txtRecip, and 'EMail' txtEmail Any ideas? Thanks in advance Fred

Private Sub btnSendEmail_Click()
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim objEmail As Variant
   
 
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application") ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
    ' Add the To recipient(s) to the message.
    objEmail = [txtEmail].Value
    response = MsgBox(objEmail)
    Set objOutlookRecip = .Recipients.Add(objEmail)
    objOutlookRecip.Type = olTo
   'response = MsgBox(txtName & Chr(13) & txtEmail)
    ' Add the CC recipient(s) to the message.
   ' Set objOutlookRecip = .Recipients.Add("")
   ' objOutlookRecip.Type = olCC

    ' Set the Subject, Body, and Importance of the message.
    .Subject = "B2B - Brethren Outreach"
    .Body = txtName.Value & "," & Chr(13) & Chr(13) & "  
FreddyBoy
  • 11
  • 1
  • 1
  • 4
  • It isn't necessary to declare Recipient or Attachment objects. I never have. I just set .To element to email string. `.To = txtEmail`. You don't show any code to include attachments. – June7 Dec 19 '22 at 05:15
  • BTW, not understanding this: "will not populate the email "To" box unless it is text, but will not if it is an email". – June7 Dec 19 '22 at 05:21
  • Thanks Jun7. I tried your suggestion .To, to no avail. When using Set objOutlookRecip = .Recipients.Add("Fred") everything works fine and is populate d as programmed. the email "to" shows Fred. But using Set objOutlookRecip = .Recipients.Add([txtEmail) it wont even create an email. and my attachments is working fine and is after the lengthy body. – FreddyBoy Dec 19 '22 at 15:25
  • Then there must be something wrong with the stored email address. – June7 Dec 19 '22 at 18:28

0 Answers0