Email Problem

Hi I am a new Programmer and i want to know how to send an automatic email when the user clicks on a button. It should pull the email address from the email field in my access database. Unfortunatly i dont know how to do this, and so far no one has been helpful. I really need to know how to do this here is my code:

Dim MyMail

MyMail = CreateObject("CDO.Message")

MyMail.Subject = "Work Order Reciept"

MyMail.From = "infosystems@dhiusa.com"

MyMail.To = 'this is where i want the email to go so it sends the user an email.

MyMail.Bcc = ""

MyMail.Cc = "jonathon_amnah@dhiusa.com"

MyMail.TextBody = "Your Issue has been received. It has been assigned to April Hopkins. Please do not reply to this E-Mail. Thank you"

MyMail.Send()

MyMail = Nothing

Please help i have spent hours on the internet searching but finding nothing.

Thanks




Answer this question

Email Problem

  • Lars Kjeldsen

    OK, it looks like your entire problem is pulling the Mail-To address from the database. You need to know a bit about the database before you can continue. Specifically, you need to know the database name, the table name, and the names of the e-mail field and all the fields you need to determine which e-mail address you want to snag.

    Now you need to learn database programming. I'm going to hand-wave a bit here, but it should get things going.

    The easiest method to get what you want is to set a TableAdapter. Add a Dataset object to your solution, and right-click in the design area and select the option create a TableAdapter. It will prompt for a connection string... for Access you want to set provider to "Microsoft Jet", and fool around a bit to get it pointing at the right database. Then it will want a query. It should look something like "SELECT eMail FROM TableName WHERE PersonName = " (plug in table name, e-mail field name, and the name of the "person's name" field).

    Now you can create an instance of the TableAdapter in your code. Call its Fill method with the person's name as an argument, and the result will be a dataset with (probably) one row. Check that row's eMail field to retrieve the data.

    Confused yet Unfortunately, database access is still a step past the beginner level, and others may suggest an easier way. But learning how to do this stuff is where programming careers are born.


  • Email Problem