List To:

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table containing email addresses and I would like to create a button
that will open an outgoing message with the "to" section populated with
query-based email addresses. I would appreciate as step-by-step instruction
as possible to help me accomplish this goal. Much appreciated.
 
Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

sqlst = "Select YourTable.EmailAddress From [YourTable] ‘SQL to get email
addresses from your table

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1 ‘Opens the recordset
If Not rs.EOF Then ‘Check to see if records are returned
eto = rs![EmailAddress]
rs.MoveNext ‘Loop through the records
While (Not (rs.EOF))
eto = eto & "; " & rs![EmailAddress]
rs.MoveNext
Wend
rs.Close
Else
eto = ""
rs.Close
End If
Set rs = nothing

Set myOlApp = CreateObject("Outlook.Application") ‘Create a outlook object
Set myitem = myOlApp.createitem(0) ‘Create a new mail item
myitem.Subject =â€Test†‘Enter Email Subject
myitem.body =â€Hi†‘Enter email body text
myitem.To = eto
myitem.display

You could also use DoCmd.SendObject instead of the code for Outlook
 
Genious...thank you....I created a list box on my form that was not visible
whose recordsource was a query that held all the e-mail addresses or records
marked "current" in my db. Then I read through the list and concatenated
(sp?) all the e-mail addresses and used the sendobject method. It always
felt like a hack way to do it. Thank you for this code.

Joey Archer


schasteen said:
Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

sqlst = "Select YourTable.EmailAddress From [YourTable] ‘SQL to get email
addresses from your table

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1 ‘Opens the recordset
If Not rs.EOF Then ‘Check to see if records are returned
eto = rs![EmailAddress]
rs.MoveNext ‘Loop through the records
While (Not (rs.EOF))
eto = eto & "; " & rs![EmailAddress]
rs.MoveNext
Wend
rs.Close
Else
eto = ""
rs.Close
End If
Set rs = nothing

Set myOlApp = CreateObject("Outlook.Application") ‘Create a outlook object
Set myitem = myOlApp.createitem(0) ‘Create a new mail item
myitem.Subject =â€Test†‘Enter Email Subject
myitem.body =â€Hi†‘Enter email body text
myitem.To = eto
myitem.display

You could also use DoCmd.SendObject instead of the code for Outlook


Vormov said:
I have a table containing email addresses and I would like to create a button
that will open an outgoing message with the "to" section populated with
query-based email addresses. I would appreciate as step-by-step instruction
as possible to help me accomplish this goal. Much appreciated.
 
Just a comment on the code.

Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

probably isn't doing what you think it is.

You can't "short circuit" declarations. Dim stDocName, eto, ecc As String
declares ecc as a String variable, but stDocName and eto as Variants (since
no data type is included). To have all 3 variables declared as Strings, you
need to use:

Dim stDocName As String, eto As String, ecc As String

So too must you use

Dim con As Object, rs As Object

to declare both variables as Objects.

Of course, given the code, I'd suggest explicitly declaring them as

Dim con As ADODB.Connection, rs As ADODB.Recordset

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Joey Archer said:
Genious...thank you....I created a list box on my form that was not visible
whose recordsource was a query that held all the e-mail addresses or records
marked "current" in my db. Then I read through the list and concatenated
(sp?) all the e-mail addresses and used the sendobject method. It always
felt like a hack way to do it. Thank you for this code.

Joey Archer


schasteen said:
Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

sqlst = "Select YourTable.EmailAddress From [YourTable] 'SQL to get email
addresses from your table

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1 'Opens the recordset
If Not rs.EOF Then 'Check to see if records are returned
eto = rs![EmailAddress]
rs.MoveNext 'Loop through the records
While (Not (rs.EOF))
eto = eto & "; " & rs![EmailAddress]
rs.MoveNext
Wend
rs.Close
Else
eto = ""
rs.Close
End If
Set rs = nothing

Set myOlApp = CreateObject("Outlook.Application") 'Create a outlook object
Set myitem = myOlApp.createitem(0) 'Create a new mail item
myitem.Subject ="Test" 'Enter Email Subject
myitem.body ="Hi" 'Enter email body text
myitem.To = eto
myitem.display

You could also use DoCmd.SendObject instead of the code for Outlook


Vormov said:
I have a table containing email addresses and I would like to create a button
that will open an outgoing message with the "to" section populated with
query-based email addresses. I would appreciate as step-by-step instruction
as possible to help me accomplish this goal. Much appreciated.
 
Thank you for the advice.

Douglas J Steele said:
Just a comment on the code.

Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

probably isn't doing what you think it is.

You can't "short circuit" declarations. Dim stDocName, eto, ecc As String
declares ecc as a String variable, but stDocName and eto as Variants (since
no data type is included). To have all 3 variables declared as Strings, you
need to use:

Dim stDocName As String, eto As String, ecc As String

So too must you use

Dim con As Object, rs As Object

to declare both variables as Objects.

Of course, given the code, I'd suggest explicitly declaring them as

Dim con As ADODB.Connection, rs As ADODB.Recordset

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Joey Archer said:
Genious...thank you....I created a list box on my form that was not visible
whose recordsource was a query that held all the e-mail addresses or records
marked "current" in my db. Then I read through the list and concatenated
(sp?) all the e-mail addresses and used the sendobject method. It always
felt like a hack way to do it. Thank you for this code.

Joey Archer


schasteen said:
Dim stDocName, eto, ecc As String
Dim sqlst As String
Dim con, rs As Object

sqlst = "Select YourTable.EmailAddress From [YourTable] 'SQL to get email
addresses from your table

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1 'Opens the recordset
If Not rs.EOF Then 'Check to see if records are returned
eto = rs![EmailAddress]
rs.MoveNext 'Loop through the records
While (Not (rs.EOF))
eto = eto & "; " & rs![EmailAddress]
rs.MoveNext
Wend
rs.Close
Else
eto = ""
rs.Close
End If
Set rs = nothing

Set myOlApp = CreateObject("Outlook.Application") 'Create a outlook object
Set myitem = myOlApp.createitem(0) 'Create a new mail item
myitem.Subject ="Test" 'Enter Email Subject
myitem.body ="Hi" 'Enter email body text
myitem.To = eto
myitem.display

You could also use DoCmd.SendObject instead of the code for Outlook


:

I have a table containing email addresses and I would like to create a button
that will open an outgoing message with the "to" section populated with
query-based email addresses. I would appreciate as step-by-step instruction
as possible to help me accomplish this goal. Much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top