Solved

Emailing Multiple Attachments from within Access II

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 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