473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Change Private Function to Public Sub/Function

I have and email button on one of my forms but I want to use that code
on a few more forms but don't want to copy the code on each form
because any changes I make to the code will need to be updated on each.
I was thinking I could use a Public Module so I can call it from
anywhere but I get the following error: External Name not defined.

It looks like it is not finding the Participant First Name from my
form. Here is my code. How can I fix this? I basically just want to
call the procedure from any form.

Public Sub SendMail()
On Error GoTo Err_cmdEmail:

'Provides the Send Mail automation
Dim dbs As DAO.Database
Dim strSubject As String
Dim strEmailAddress As String
Dim strCCEmail As String
Dim strEMailMsg As String
strSubject = "Employment verification for:" & " " & [Participant First
Name] & " " & [Participant Last Name] & " " & ", Please respond- 6
Month Check"
strEmailAddress = "em********@123.com"
strBCCEmail = [SupervisorEmail] & "; " & [HRContactFax] &
"@faxmail.com; " & [HRContactEmail]

Set dbs = CurrentDb
strEMailMsg = "Written Request for Employment Verification." _
& Chr(10) & "Today's Date:" & " " & Date & Chr(10) & Chr(10) _
& "Re:" & " " & [Participant First Name] & " " & [Participant Last
Name] & Chr(10) & Chr(10) & "Hello," _
& Chr(10) & Chr(10) & "The below information is currently on record
for:" & " " & [Participant First Name] & " " & [Participant Last Name]
_
& Chr(10) & Chr(10) & "Employer: " & " " & [OrganizationName] _
& Chr(10) & "Job Title: " & " " & [Job Description] _
& Chr(10) & "Pay Rate: " & " $" & [Starting Pay] & Chr(10) &
"Status (Full or Part time): " & " " & [Hours] _
& Chr(10) & "Start Date: " & " " & [BeginDate] _
& Chr(10) & Chr(10) & "To verify this information please do one of
the following:" _
& Chr(10) & Chr(10) & "1. Have Human Resources, or the immediate
supervisor make any changes or" _
& "corrections and return this letter via email or fax to Company
Name along with the Supervisor's " _
& "name and full contact information. Email: em********@123.com
Fax:" _
& Chr(10) & Chr(10) & "2. Fax a copy of the most recent paycheck
stub to (123) 456-7891. " _
& "Please make sure that the above information, Employee Name,
Company Name, Job Title, Pay Rate, " _
& "and Hours per week are included on or with the paycheck stub." _
& Chr(10) & Chr(10) & "I would greatly appreciate your response as
soon as possible but no later " _
& "than (Date). Keeping our information current enables us to keep
the terms of our grant contracts " _
& "and ensures that we will continue to receive the grants and
resources that make Company Name possible. Thanks for your help! " _

'EMAIL USER DETAILS & ATT REPORT
DoCmd.SendObject , , html, strEmailAddress, _
, strBCCEmail, strSubject, strEMailMsg, True, False
Err_cmdEmail:

If Err.Number = 2295 Then
MsgBox "There are no email addresses for the Supervisor or HR
Contact. The email message was not generated. Enter in valid email
addresses and try again.", _
vbInformation, "Email Message Can Not be Sent."

End If

End Sub

Thanks

Aug 31 '06 #1
1 3599
mchlle wrote:
I have and email button on one of my forms but I want to use that code
on a few more forms but don't want to copy the code on each form
because any changes I make to the code will need to be updated on each.
I was thinking I could use a Public Module so I can call it from
anywhere but I get the following error: External Name not defined.

It looks like it is not finding the Participant First Name from my
form. Here is my code. How can I fix this? I basically just want to
call the procedure from any form.
You might want to pass the form or form name to the proc
So...
Public Sub SendMail(frm As Form)
would be the first thing.

Then use
frm![Participant Last Name]
when referencing the field
>
Public Sub SendMail()
On Error GoTo Err_cmdEmail:

'Provides the Send Mail automation
Dim dbs As DAO.Database
Dim strSubject As String
Dim strEmailAddress As String
Dim strCCEmail As String
Dim strEMailMsg As String
strSubject = "Employment verification for:" & " " & [Participant First
Name] & " " & [Participant Last Name] & " " & ", Please respond- 6
Month Check"
strEmailAddress = "em********@123.com"
strBCCEmail = [SupervisorEmail] & "; " & [HRContactFax] &
"@faxmail.com; " & [HRContactEmail]

Set dbs = CurrentDb
strEMailMsg = "Written Request for Employment Verification." _
& Chr(10) & "Today's Date:" & " " & Date & Chr(10) & Chr(10) _
& "Re:" & " " & [Participant First Name] & " " & [Participant Last
Name] & Chr(10) & Chr(10) & "Hello," _
& Chr(10) & Chr(10) & "The below information is currently on record
for:" & " " & [Participant First Name] & " " & [Participant Last Name]
_
& Chr(10) & Chr(10) & "Employer: " & " " & [OrganizationName] _
& Chr(10) & "Job Title: " & " " & [Job Description] _
& Chr(10) & "Pay Rate: " & " $" & [Starting Pay] & Chr(10) &
"Status (Full or Part time): " & " " & [Hours] _
& Chr(10) & "Start Date: " & " " & [BeginDate] _
& Chr(10) & Chr(10) & "To verify this information please do one of
the following:" _
& Chr(10) & Chr(10) & "1. Have Human Resources, or the immediate
supervisor make any changes or" _
& "corrections and return this letter via email or fax to Company
Name along with the Supervisor's " _
& "name and full contact information. Email: em********@123.com
Fax:" _
& Chr(10) & Chr(10) & "2. Fax a copy of the most recent paycheck
stub to (123) 456-7891. " _
& "Please make sure that the above information, Employee Name,
Company Name, Job Title, Pay Rate, " _
& "and Hours per week are included on or with the paycheck stub." _
& Chr(10) & Chr(10) & "I would greatly appreciate your response as
soon as possible but no later " _
& "than (Date). Keeping our information current enables us to keep
the terms of our grant contracts " _
& "and ensures that we will continue to receive the grants and
resources that make Company Name possible. Thanks for your help! " _

'EMAIL USER DETAILS & ATT REPORT
DoCmd.SendObject , , html, strEmailAddress, _
, strBCCEmail, strSubject, strEMailMsg, True, False
Err_cmdEmail:

If Err.Number = 2295 Then
MsgBox "There are no email addresses for the Supervisor or HR
Contact. The email message was not generated. Enter in valid email
addresses and try again.", _
vbInformation, "Email Message Can Not be Sent."

End If

End Sub

Thanks
Aug 31 '06 #2

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

Similar topics

4
by: pjac | last post by:
I need some help with some VB language that will change the screen resolution on a monitor when a MS-Access 2000 database is opened from 1024 x 768 to 800 x 600. Any help with this effort would be...
8
by: lauren quantrell | last post by:
Is there a way to force a change in a user's screen resolution using VBA code without having any input from the user? Example: User John Backwards has his screen set to 800 x 600 pixels. Backwards...
0
by: MS | last post by:
Is the schema used to validate XML Documentation Comments available to be changed by a VS.Net user? I suspect the this question is no so have a couple of requests: 1.) I use #region...
7
by: Peter Oliphant | last post by:
I use to make the statement that you could always replace any 'private' or 'public' access with 'public' and the code would still compile. This is no longer the case. It turns out that in /clr...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
9
by: aleplgr | last post by:
Hi! I'm trying to let the end-user select the language of the menues I'm showing him. To do that I've got this Selector class that shows the end user a combo box, a label and a button. In the combo...
0
by: Composer | last post by:
More experienced programmers may laugh that I had to struggle with this, but I post it so that others in my position might benefit. My application allows the user to have many forms open. Some...
1
by: chromis | last post by:
Hi, I've been trying to create a carousel class which takes an array of phrases and then creates a textfield for each one positioning it vertically based on the order it was added. The next stage...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.