Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Email problem

  1. #1
    Join Date
    Sep 2001
    Posts
    175

    Question Unanswered: Email problem

    I have an Acess 2002 database in which I store client information including their email addresses.

    How can I use the email addresses stored in the database to email word or other type documents to them? I use MS Outlook/MS Exchange as my email program.

    Please help....

  2. #2
    Join Date
    Mar 2003
    Location
    London
    Posts
    40

    Re: Email problem

    I assume you do not have to log on to your Outlook. If you do, write back to me and I'll tell you how.

    Here's sample code you can use to automatically create mail messages.

    Do not forget to reference MS Outlook 9.0 library in your project's references.

    public sub MailWithAttachments()
    Set objOutlook = New Outlook.Application
    Set objMailItem = objOutlook.CreateItem(olMailItem)
    objMailItem.Recipients.Add "some-user@some-domain.com"
    objMailItem.Recipients.Add "another-user@another-domain.com"
    objMailItem.Subject = "This is a test e-mail with attachements"
    objMailItem.Attachments.Add _
    "Full path to the file to attach, e.g. c:\temp\doc1.doc", _
    olByValue, _
    Len(objMailItem.Body), _
    "Display name of the attachment (not doc1.doc)"
    objMailItem.Attachments.Add _
    "Full path to the file to attach, e.g. c:\temp\doc2.doc", _
    olByValue, _
    Len(objMailItem.Body), _
    "Display name of the attachment (not doc2.doc)"
    objMailItem.Send
    set objMailItem=nothing
    set objOutlook = nothing
    end sub

  3. #3
    Join Date
    Sep 2001
    Posts
    175

    Question Re: Email problem

    Thanks for your assistance. Just a few questions though.

    Not sure what you mean my 'reference MS Outlook 9.0 library in your project's references'

    In the code where you have 'objMailItem.Recipients.Add "some-suer@some-domain.com" - does that mean I have to list all the email addresses or can I do it say based on a report that gives me all the email addresses based on some criteria???

  4. #4
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820

    Re: Email problem

    Originally posted by toukey1
    Thanks for your assistance. Just a few questions though.

    Not sure what you mean my 'reference MS Outlook 9.0 library in your project's references'

    In the code where you have 'objMailItem.Recipients.Add "some-suer@some-domain.com" - does that mean I have to list all the email addresses or can I do it say based on a report that gives me all the email addresses based on some criteria???
    open the VBA editor (alt + F11), got to the tools menu, click references and ensure that the reference 'Microsoft Outlook X.X Object Libray' is checked (with office XP it sould be 10.0)
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  5. #5
    Join Date
    Sep 2001
    Posts
    175

    Re: Email problem

    Thanks - got that settled now.

  6. #6
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820

    Re: Email problem

    also the code i use is
    Code:
    Sub SendMail(EmailAddresses as String, EmailSubject as String, Message as String, filename as String)
        Dim email As Outlook.MailItem
        Set email = CreateObject("Outlook.Application").CreateItem(olMailItem)
        email.To = EmailAddresses 
        email.Subject = EmailSubject 
        email.Body = Message
        if filename <>"" then email.Attachments.Add filename
        email.Send   
    End Sub
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  7. #7
    Join Date
    Sep 2001
    Posts
    175

    Re: Email problem

    Your code seems a lot easier but in the line email.to = emailaddresses is that to one (1) address or can I use a report that will give me say all the email addresses for clients who have monies outstanding for the month of March?

  8. #8
    Join Date
    Sep 2001
    Posts
    175

    Re: Email problem

    Where does your code go???

  9. #9
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820

    Re: Email problem

    Originally posted by toukey1
    Where does your code go???
    either on the form or in a module but it you put in a module change it to public sub

    as for the addresses you can pass it 1 address or multiple just seperate them with a '; ' as you would if typing the addresses in the to field

    the way you'd call mine is
    Code:
    SendMail "Someone@somewhere.com", "Subject","Message", "Filename"
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  10. #10
    Join Date
    Sep 2001
    Posts
    175

    Re: Email problem

    Is there a way to get the addresses from what the user has entered in the form? There would be several hundred addresses and I am trying to avoid having to enter them twice as well as keeping the list in your code updated. I was thinking of doing a report that would create a list of the addresses based on a criteria and somehow use those addresses in the code

  11. #11
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Several Hundred Emails, what are you doing a auto spammer?

    any way my code should accept them as long as you've formated the addresses correctly as for doing the formating that depends on the forms your using but should be possible,

    answer the following questions and i should be able to give you a more detailed response

    1 are the addresses stored in a table, if this isn't ansered yes your in for some fun

    2 are all the addresses shown on 1 form

    3 are the emails generated on the same for as the addresses are avalable

    btw my code doesn't maintain a list of emails it only knows those that are given to it directly that time
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  12. #12
    Join Date
    Sep 2001
    Posts
    175
    NO this has nothing to do with spamming.

    My table has the following fields:

    clientname, address1, address2, address3, emailaddress, AE etc. So, YES the addresses are stored in a table and they are all entered on the same form which is based on the table.

    I also need it based on a criteria because I want to send different publications to different people, that is why I was hoping to base it on a query or something.

    Hope this helps you somewhat.

    Thanks

  13. #13
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by toukey1
    NO this has nothing to do with spamming.

    My table has the following fields:

    clientname, address1, address2, address3, emailaddress, AE etc. So, YES the addresses are stored in a table and they are all entered on the same form which is based on the table.

    I also need it based on a criteria because I want to send different publications to different people, that is why I was hoping to base it on a query or something.

    Hope this helps you somewhat.

    Thanks
    Then i think you'll need something like:

    Dim rs As DAO.Recordset, tmpStr as String
    set rs = currentDB.openrecordset("<QueryName>", dbOpenSnapshot, dbReadOnly)
    rs.movefirst
    While Not rs.EOF
    if tmpStr <> "" then
    tmpStr = tempStr & "; " & rs("emailaddress").value
    else
    tmpstr = rs("emailaddress").value
    end if
    rs.movenext
    Wend

    and then feed tmpStr into the earlier sub
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  14. #14
    Join Date
    Sep 2001
    Posts
    175
    Thanks. I will give it a try and post the outcome.

  15. #15
    Join Date
    Sep 2001
    Posts
    175
    When I ran the code below in VB, I keep getting tmpStr equal to only the first email address although it does the loop. Also you said to feed tmpStr into the first code that you gave me but where do I put that code? Do I put it as a separate Sub or can I put it following the one below? I am not too familar with VB



    Dim rs As DAO.Recordset, tmpStr as String
    set rs = currentDB.openrecordset("<QueryName>", dbOpenSnapshot, dbReadOnly)
    rs.movefirst
    While Not rs.EOF
    if tmpStr <> "" then
    tmpStr = tempStr & "; " & rs("emailaddress").value
    else
    tmpstr = rs("emailaddress").value
    end if
    rs.movenext
    Wend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •