Link to home
Start Free TrialLog in
Avatar of dawber39
dawber39Flag for United States of America

asked on

Emailing Multiple Attachments from within Access II

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
Avatar of dawber39
dawber39
Flag of United States of America image

ASKER

In addition  - I tried it with both .Attachment, and poSendMail.Attachment formats
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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!!