By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

Send email from Access

P: n/a
I would like to send an email from Access. I copied the code from another
free website, but it does not do everything I need it to do. I have a series
of checkboxes:

checkbox1 - when checked, I want to display orange
checkbox2 - when checked, I want to display apples
checkbox3 - when checked, I want to display grapes
If all three checked, I want to display in one column:
orange
apples
grapes

So what I want to do is in the body of the email, have "Thank you for
ordering our fruit. We show you ordered the below fruits:

orange
apples
grapes
(depending on what checkboxes were checked, put in the fruits ordered.)

Then I want a closing paragraph,i.e.
We look forward to your business in the future.

Sincerely,

Here's my code so far. Thanks in advance.

How do I incorporate the option to put in my checkboxes on the form:

Private Sub Command29_Click()
On Error GoTo Err_Command0_Click

Dim stext As String
Dim sAddedtext As String

If Len(txtMainAddresses) Then
stext = txtMainAddresses
End If
If Len(txtCC) Then
sAddedtext = sAddedtext & "&CC=" & txtCC
End If
If Len(txtBCC) Then
sAddedtext = sAddedtext & "&BCC=" & txtBCC
End If
If Len(txtSubject) Then
sAddedtext = sAddedtext & "&Subject=" & txtSubject
End If
If Len(txtBody) Then
sAddedtext = sAddedtext & "&Body=" & txtBody
End If
If Len(txtAttachment) Then
sAddedtext = sAddedtext & "Attach=" & Chr$(34) & txtAttachment & Chr$
(34)
End If

stext = "mailto:" & stext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If

stext = stext & sAddedtext & myString

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
SW_SHOWNORMAL)
End If
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
'End If
End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
icsupt via AccessMonster.com wrote:
I would like to send an email from Access. I copied the code from another
free website, but it does not do everything I need it to do. I have a series
of checkboxes:

checkbox1 - when checked, I want to display orange
checkbox2 - when checked, I want to display apples
checkbox3 - when checked, I want to display grapes
I suggest you name your checkboxes, something like
chkOrange
chkApple

etc. :-)
So what I want to do is in the body of the email, have "Thank you for
ordering our fruit. We show you ordered the below fruits:

orange
apples
grapes
(depending on what checkboxes were checked, put in the fruits ordered.)

Then I want a closing paragraph,i.e.
We look forward to your business in the future.

Sincerely, Private Sub Command29_Click()
On Error GoTo Err_Command0_Click

Dim stext As String
Dim sAddedtext As String [snip] If Len(txtBody) Then
sAddedtext = sAddedtext & "&Body=" & txtBody
End If


It appears to me the whole email message is taken from the control
txtBody. It is probably not this routine that should insert the fruits,
but some other event on the form.

Or, you'd have to split up the text, according to some parameter
indicator (Mac uses ^1, ^2 ... for variable texts in its code, I like
that) and insert values. Just before this if...end if is the place to do
this.

Have a look at docmd.sendobject acsendnoobject as well. You can send a
message with 'native' code, if you have a registered email client on the
machine running Access.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html

Nov 13 '05 #2

P: n/a
icsupt via AccessMonster.com wrote:
I would like to send an email from Access. I copied the code from another
free website, but it does not do everything I need it to do.

<snip>

What you really might want to try is using the CDONTS object. In VBA, do
Tools->References, and look for the "Microsoft CDO for NTS" library.

This will let you send to an SMTP gateway, for example, and probably the
most important for you, lets you define the From and Reply-To values
(even for Exchange...). Most of the other methods depend on you having
Outlook active and hooked up to Exchange, and will refer the e-mail sent
back to your e-mail account, and won't let you set the From or Reply-To
values to a different mail box.

when installing Outlook 2003, I think if you do a Custom installation,
it's an X'd-out option, but if you check it, it'll be included.

It's old-school, but it's really the most flexible method, especially if
you are not using Exchange & Outlook.

There is some trickery involved if you are indeed using Exchange but
don't have Outlook open, because you need it to login to Exchange as you.
Nov 13 '05 #3

P: n/a
corey lawson wrote:
icsupt via AccessMonster.com wrote:
I would like to send an email from Access. I copied the code from another
free website, but it does not do everything I need it to do.

<snip>

What you really might want to try is using the CDONTS object. In VBA, do
Tools->References, and look for the "Microsoft CDO for NTS" library.

This will let you send to an SMTP gateway, for example, and probably the
most important for you, lets you define the From and Reply-To values
(even for Exchange...). Most of the other methods depend on you having
Outlook active and hooked up to Exchange, and will refer the e-mail sent
back to your e-mail account, and won't let you set the From or Reply-To
values to a different mail box.

when installing Outlook 2003, I think if you do a Custom installation,
it's an X'd-out option, but if you check it, it'll be included.

It's old-school, but it's really the most flexible method, especially if
you are not using Exchange & Outlook.

There is some trickery involved if you are indeed using Exchange but
don't have Outlook open, because you need it to login to Exchange as you.


There is also the pure SMTP method that Tony has documented on his
site, which doesn't require CDO at all.

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.