473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need Help with Code to Email from Form

I have a form in Access 97 on which I have an unbound list box filled
with our employees names from tblEmployees. When you select an
employee's name and click a button, the following code is run and
another form opens with only that employee's data:

For Each varSelected In Me!EmpList.ItemsSelected
strSQL = strSQL & Me!EmpList.ItemData(varSelected) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWeeks", acViewNormal, , strSQL

I have a textbox on the frmVacationWeeks called txtEmail. I need to
be able to click a button on this form that will automatically email a
report called rptApprovedVac only to the employee whose email address
is in txtEmail. I will appreciate any help you can give me on this.

Thanks,
JD
Nov 12 '05 #1
5 4462
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use the SendObject method of the DoCmd object - see the help topic
SendObject.

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP4r3LIechKqOuFEgEQImNQCfdiYZ016v8h9UTnT7RLkD6o v7174An06V
PIPy/+g6D/TKrSfAe9jPhwqS
=JzP/
-----END PGP SIGNATURE-----

jd****@yahoo.com wrote:
I have a form in Access 97 on which I have an unbound list box filled
with our employees names from tblEmployees. When you select an
employee's name and click a button, the following code is run and
another form opens with only that employee's data:

For Each varSelected In Me!EmpList.ItemsSelected
strSQL = strSQL & Me!EmpList.ItemData(varSelected) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWeeks", acViewNormal, , strSQL

I have a textbox on the frmVacationWeeks called txtEmail. I need to
be able to click a button on this form that will automatically email a
report called rptApprovedVac only to the employee whose email address
is in txtEmail. I will appreciate any help you can give me on this.

Thanks,
JD


Nov 12 '05 #2
jd****@yahoo.com (jd****@yahoo.com) wrote in message news:<75**************************@posting.google. com>...
I have a form in Access 97 on which I have an unbound list box filled
with our employees names from tblEmployees. When you select an
employee's name and click a button, the following code is run and
another form opens with only that employee's data:

For Each varSelected In Me!EmpList.ItemsSelected
strSQL = strSQL & Me!EmpList.ItemData(varSelected) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWeeks", acViewNormal, , strSQL

I have a textbox on the frmVacationWeeks called txtEmail. I need to
be able to click a button on this form that will automatically email a
report called rptApprovedVac only to the employee whose email address
is in txtEmail. I will appreciate any help you can give me on this.

Thanks,
JD


Either use the SendObject command or automate Outlook. (If you're
only mailing to one person at a time, why are you using a listbox?)
You could just loop through the ItemsSelected collection of the
listbox and inside the loop use SendObject command. Nothing doing.
Nov 12 '05 #3
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf*************************@posting.google.c om>...

Either use the SendObject command or automate Outlook. (If you're
only mailing to one person at a time, why are you using a listbox?)
You could just loop through the ItemsSelected collection of the
listbox and inside the loop use SendObject command. Nothing doing.


I developed a Vacation database and I am using the listbox on a form
that has several options - when an employee's name is selected in the
listbox, one can view and print reports with only that employee's
data, and open a form on which the employee can post dates he wants to
take off from work. On another form, after an employee's name is
selected in the listbox, the supervisor can approve or reject dates
the employee has requested to take off. It is on this form that I
need a button I can have the supervisors click to automatically email
the employee whose name appears on the form. I used SendObject, but
when I used this, I had to manually type the employee's name in the
"To" line of message box. My boss wants this automated - he doesn't
want the supervisors to have to type the employee's name. Any
suggestions?

Thanks,
JD
Nov 12 '05 #4
jd****@yahoo.com (jd****@yahoo.com) wrote in message news:<75**************************@posting.google. com>...
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf*************************@posting.google.c om>...

Either use the SendObject command or automate Outlook. (If you're
only mailing to one person at a time, why are you using a listbox?)
You could just loop through the ItemsSelected collection of the
listbox and inside the loop use SendObject command. Nothing doing.


I developed a Vacation database and I am using the listbox on a form
that has several options - when an employee's name is selected in the
listbox, one can view and print reports with only that employee's
data, and open a form on which the employee can post dates he wants to
take off from work. On another form, after an employee's name is
selected in the listbox, the supervisor can approve or reject dates
the employee has requested to take off. It is on this form that I
need a button I can have the supervisors click to automatically email
the employee whose name appears on the form. I used SendObject, but
when I used this, I had to manually type the employee's name in the
"To" line of message box. My boss wants this automated - he doesn't
want the supervisors to have to type the employee's name. Any
suggestions?

Thanks,
JD

Say you have a combobox or a listbox with two columns. One shows the
employee's name, and the other shows the employee's e-mail address.
Then you could just pass the proper column value to the SendObject
function, and you should be ready to go. Something kinda like this...
without all the message box rubbish (just to check that I can see all
this stuff...)

Private Sub Command4_Click()
Dim strName As String
Dim strEMail As String

strName = Me.List2.Column(0)
strEMail = Me.List2.Column(1)

MsgBox "Name: " & strName & vbCrLf & "E-Mail:" & strEMail,
vbOKOnly
DoCmd.SendObject acSendReport, "In House for Pickup",
acFormatHTML, strEMail, , , "See attached Report", "Like my report?"
End Sub

Column(0) is visible (width is non-zero)
Column(1) is not visible (width=0)

Then you just grab the e-mail addresses from a query or table...

SELECT FName & " " & LName As StaffName, EMailAddress
FROM Staff
ORDER BY FName, LName;

or whatever you want...

HTH,
Pieter
Nov 12 '05 #5
jd****@yahoo.com (jd****@yahoo.com) wrote in message news:<75**************************@posting.google. com>...
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf*************************@posting.google.c om>...

Either use the SendObject command or automate Outlook. (If you're
only mailing to one person at a time, why are you using a listbox?)
You could just loop through the ItemsSelected collection of the
listbox and inside the loop use SendObject command. Nothing doing.


I developed a Vacation database and I am using the listbox on a form
that has several options - when an employee's name is selected in the
listbox, one can view and print reports with only that employee's
data, and open a form on which the employee can post dates he wants to
take off from work. On another form, after an employee's name is
selected in the listbox, the supervisor can approve or reject dates
the employee has requested to take off. It is on this form that I
need a button I can have the supervisors click to automatically email
the employee whose name appears on the form. I used SendObject, but
when I used this, I had to manually type the employee's name in the
"To" line of message box. My boss wants this automated - he doesn't
want the supervisors to have to type the employee's name. Any
suggestions?

Thanks,
JD


Addendum to above post: I modified my code in the OnClick event of the
button on my form to the following (thanks to someone in this NG):
DoCmd.SendObject acSendReport, "rptReportName", "Snapshot Format",
Me.txtEMail, , , "Subject", "Message Body." This keeps me from having
to type in the employee's name - I just have to click Send when the
message box pops up, but I still need to automate this so it happens
in the background and the user needs to do nothing but click the
button. Thanks in advance for any tips.

JD
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding...
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
3
by: mcse4u | last post by:
I would like to be able to add a hyperlink to the posted form below that automatically creates a hyperlink of the email address of the person submitting the form. Can someone please help me with...
17
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
14
by: confusedfusion | last post by:
Not sure how many form submissions that have been lost over the years before I started but the company has a contact form that the required fields when validation fails the error message is going...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.