Solved

Emailing Multiple Attachments from within Access II

Posted on 2012-04-05
4
691 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
Comment Utility
In addition  - I tried it with both .Attachment, and poSendMail.Attachment formats
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
Try this instead.

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

Expert Comment

by:Jeffrey Coachman
Comment Utility
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
Comment Utility
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now