Solved

Emailing Multiple Attachments from within Access II

Posted on 2012-04-05
4
697 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
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

820 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