Solved

Emailing Multiple Attachments from within Access II

Posted on 2012-04-05
4
698 Views
Last Modified: 2012-06-27
Good afternoon all

I am using a previous suggestion of using vbSendMail to email multiple attachments from within Access. The vbSendmail in my testing environment works fine with the accompanying form that does not allow for attachments. I found some code specific to adding attachments to vbSendmail, I added the necessary text boxes (Text20 & Text22) to the form, and I tried it with the following error:
 Run-time error 2185

You can't reference a property or method for a control unless the control has the focus

It gets hung up on a line that I added:

.Attachment = Text20.Text & ";" & Text22.Text (this line and the text boxes is all I added)

In these text boxes, I have the path to the file (C:\Users\Rick\Desktop\Roche\Test1.pdf - and so on)

Option Compare Database
Option Explicit

Private WithEvents poSendMail As MyMail.clsSendMail
' Reference to c:\windows\system\MyMail.OCX
'
Private Sub btnSend_Click()
    btnSend.Caption = "Sending"
    Set poSendMail = New MyMail.clsSendMail
    With poSendMail
        .SMTPHost = Form!txtServer             ' Required the fist time, optional thereafter
        .From = Form!txtFrom                        ' Required the fist time, optional thereafter
        .FromDisplayName = Form!txtFromName         ' Optional, saved after first use
        .Message = "<HTML><BODY>" & Form!txtMsg & "</BODY></HTML>"
        .AsHTML = True ' Optional
        .Recipient = Form!txtTo
        .RecipientDisplayName = Form!txtToName
        .Subject = Form!txtSubject
         poSendMail.Attachment = Text20.Text & ";" & Text22.Text
        .RequestReceipt = Form!cbRequestReadReceipt
        .Send
    End With
End Sub


Private Sub poSendMail_Progress(PercentComplete As Long)
    Debug.Print "poSendMail_Progress " & PercentComplete
    Form!lblProgress.Caption = "Progress: " & PercentComplete & "%"
    Form!lblProgress.Visible = True
    Form.Repaint
End Sub

Private Sub poSendMail_SendFailed(Explanation As String)
    'Debug.Print "poSendMail_SendFailed " & Explanation
    Form!btnSend.Caption = "Not Sent"
    MsgBox Explanation, vbInformation + vbOKOnly, "Send Failed"
    'Form!lblStatus.Caption = "Send failed: " & Explanation
    Form!lblStatus.Visible = False
    Form.Repaint
End Sub

Private Sub poSendMail_SendSuccesful()
    Debug.Print "poSendMail_SendSuccesful "
    Form!lblStatus.Caption = "Sent Successfully"
    Form!lblStatus.Visible = False
    Form!btnSend.Caption = "Sent!"
    Form.Repaint
End Sub

Private Sub poSendMail_Status(Status As String)
    Debug.Print "poSendMail_Status " & Status
    Form!lblStatus.Caption = Status
    Form!lblStatus.Visible = True
End Sub


Any help would be appreciated


Below is the entire code for the form - and I have included the sample I am working with
SendMaiExample.accdb
SendMailOriginal.mdb
0
Comment
Question by:dawber39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:dawber39
ID: 37813565
In addition  - I tried it with both .Attachment, and poSendMail.Attachment formats
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 37813719
Try this instead.

.Attachment = Text20 & ";" & Text22
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37813764
That should fix the:
 "You can't reference a property or method for a control unless the control has the focus"
...error, because to access the text property, the control need to have the focus.
90% of the time, all you need from a textbox is the "value" (ex.: txtLastName.Value)

.Value is the default, ...so all you need is "txtYourTextBox"

...not sure if this will then let you do your attachment stuff though...
;-)

Jeff
0
 

Author Closing Comment

by:dawber39
ID: 37813993
Awesome - worked like a charm. I gather that because I had the .text in the code - that it was looking to attach what was contained in the textbox? .. You people up here are the BESTEST!!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question