Send Attachments with ListBox Values

Ksabai

Registered User.
Local time
Today, 00:03
Joined
Jul 31, 2017
Messages
104
Iam trying to Open an Outlook email Windows with the Below Codes:

Dim i As Integer
Dim strlstData As String
Dim AttachFile As String

For i = 0 To Me.lstEmails.ListCount - 1
strlstData = strlstData & Me.lstEmails.ItemData(i) & ";"
Next i

AttachFile = strlstData
Call SendHTMLEmail(" ", " ", " ", True, , Array(AttachFile))

Error Description is File Name or Directory Name is not Valid.

if the lstBox has one file i dont have a problem. I think the issue is with the file seperator. have tried : , ; . but getting the same error. Tried after strlstData as well. both resulting in the same error
 
iam getting error method or data member not found in the line

.ScreenUpdating =
 
That line is not shown in your code. Post your entire procedure and please use CODE tags.

I have never used ScreenUpdating nor EnableEvents.
 
Sorry this is my Code

Dim strLocation As String
Dim strlstData As String
Dim i As Integer

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.subject = "This is the Subject line"
.Body = "Hello World!"

For i = 0 To Me.lstEmails.ListCount - 1
strlstData = sFolder & Me.lstEmails.ItemData(i)
strLocation = strlstData
.Attachments.Add (strLocation)
.Display
Next i
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
 
Please use CODE tags in post so code will retain indentation and readability.

Still haven't explained if you want multiple emails each with 1 attachment or 1 email with multiple addresses and multiple attachments.

You need to provide an email for the TO element.

Is the listbox a list of email addresses or a list of attachment file paths?

Code is looping through listbox and including every item. Is that what you really want?

Why set strLocation = strlstData? Since they are equivalent just use strlstData.

Maybe eliminate the ScreenUpdating and EnableEvents lines.
 
Last edited:
i want 1 email with multiple attachment, everything is fine after removing screenupdate and Enable events, thanks also set strlstdata as the string
 
In fact, neither variable is needed with your code.

.Attachments.Add (sFolder & Me.lstEmails.ItemData(I))

But how is sFolder declared and populated?
 
its a public function, Thanks for the above - its working fine now
 
For info, neither ScreenUpdating nor EnableEvents are valid commands in Access. You may be thinking of similar commands in Excel

To pause screen updating in Access, use Application.Echo False then to resume use Application.Echo True

To pause code to allow the processor to complete the previous task, you can use: DoEvents
 
DoEvents ???, can u please add them in the above Code. iam not really that good
 
I don't think it's necessary to use DoEvents with your code.

I often use it with progress bar code to ensure the screen display is updated correctly in lengthy procedures. However it means code runs slightly slower due to added 'pauses'
 
You cannot just take any piece of code and expert it to work in your scenario.
I offered that code to show how you add attachments (or at least I have in the past) in Outlook.

ScreenUpdating is in Excel, so that code was obviously being called from within Excel.
Here is a link where I have Googled for '

add attachment to email access vba

iam getting error method or data member not found in the line

.ScreenUpdating =
 

Users who are viewing this thread

Back
Top Bottom