Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems while sending Emails from Access2000 thru Outlook

Status
Not open for further replies.

Basey

Programmer
Jan 9, 2002
4
DE
Hi!

I have a table which contains Baseball-Cards and I have a table containing collectors with email-adresses, search strings and addresses.

I seek the DB and get all matches of search strings and cards. The results are kept in a temp-txtfile.

In the next step this tmpfile is read line by line and the email is generated one after the next. (should be)

The problem now is, that only the first msg is produced, the next ones not, the first is not sendable, as it's placed into the inbox of outlook...

Following the code and my explanations. Any help?

If sLine = "#!EMAIL-ENDE!#" Then
If txtMainAddresses <> &quot;&quot; And bolCards = True Then
DoCmd.SendObject acSendNoObject, , _
acFormatTXT, _
txtMainAddresses, , , _
txtSubject, txtBody, True

txtMainaddresses contains one email-address
txtsubject is a string with the Subject and txtBody contains the cardslist as a long string with Cr's and Lf's

If I set True to False, either I get only one email, in a second run I get nothing...

HEEEELP!
 
Basey,
Here's some code that I used in one of my e-mail dbases. This might help steer you in the right direction if you edit it to your needs. This is a module...

Sub SendOutlookMail()
On Error GoTo Errhandler
Dim DB As Database
Dim DB2 As Database
Dim RS As Recordset
Dim RS2 As Recordset
Set DB = CurrentDb()
Set RS = DB.OpenRecordset(&quot;qrysendtest&quot;) 'whatever table or query you want
Dim aCounter As Integer
Dim PersonSendTo As String
Dim aFileName As String

Do While Not RS.EOF
RS.Edit

PersonSendTo = RS! 'RS is the first recordset, EMail is the field in the table it utlizes
RS![DateSend] = Now()
RS.Update

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject(&quot;Outlook.Application&quot;)
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set DB2 = CurrentDb()
Set RS2 = DB2.OpenRecordset(&quot;tblDocument&quot;) 'this holds the filepaths of the files I'm sending
With MailOutLook
.To = PersonSendTo 'Personsendto, subject, sendmsg, are all text boxes in my form that the user can edit freely.
.Subject = SubjectLine
.HTMLBody = SendMsg & &quot;<br><br>&quot;

Do While Not RS2.EOF
RS2.Edit

aFileName = RS2![File] 'filepath field (as many as I want)
RS2.Update

.Attachments.Add aFileName, olByValue, 1, &quot;File&quot; & aCounter
aCounter = aCounter + 1

RS2.MoveNext

Loop
'.Attachments.Add aFileName, olByValue, 1, &quot;File&quot; & aCounter
.Send
End With

RS.MoveNext
Set DB2 = Nothing
Set RS2 = Nothing
Loop

Set RS = Nothing
Set DB = Nothing

Exit_sub:
Exit Sub

Errhandler:
'GoTo Exit_sub
MsgBox Err.Description

End Sub

Hey, this code has been awesome for me. Let me know if you need anything else or if it helps at all.

-Josh -Happen609
[b]Wasting more of your valuable time...[/b]
 
Thanks Josh!

It goes to the right direction... I found a solution yesterday which uses many of the things you describe here, but I will keepo that example in my &quot;personal knowledge base&quot; :)

Main thing was to access Outlook by defining the Email-parts with
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem

The simple DoCmd.SendObject does not work but I don't mind if my application needs an outlook on the system as it's always run on an MSOffice equipped computer anyway.

But just for the case: Do you know, how to check in a sub or function, if the computer has Outlook (or any other Office Application) installed? I mean if somebody wants to use my code and has no Outlook, he will propably be presented with a runtime error at the moment, no?

Thanks again, Ralf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top