Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit (mail to) command button on Access forms 1

Status
Not open for further replies.

swan717

MIS
May 16, 2001
13
US
I am in the process of designing a form to act as a user interface. The form is for internal requests for information/project assistance. Basically the person will enter the criteria for the project or information that they need and will hit a submit button. I would then like the information emailed to myself. Is this possible and if so how?

Thanks!
 
you will need to create a report with the information you want sent to you. use this code in the submit button:

stDocName = "your report name"
DoCmd.SendObject acReport, stDocName, acFormatTXT, "kerrigirrl@yahoo.com", , , "EMAIL SUBJECT", "Any additional text you want in the message."

the user will only have to press the send button on their email.

acFormatTXT can be acFormatHTML, acFormatRTF or acFormatXLS. The report will come out different in each one, so it's better to test before you decide. If you leave that part blank, it will let you choose out of the four. You will lose a lot of your formatting. (If you need something underlined, instead of drawing a line in the report, make sure you actually underline the text.)

i know you can send other types of date (acReport), but i've never tried it.

kerri
 
I have a form where the "Email" button is used to send an email to the address in the text box next to it. You could either use a textbox (lock it to prevent changes) or just hard code your email address.

There are two routines here: One behind the button (it checks for a text value but doesn't do Instr([txt],"@") which might be the complete validation check for an email) and one that is called from a module. I keep the second routine in the module so that several buttons may use it:

[tt]
Private Sub cmdSCEmail_Click()
On Error GoTo ErrorTrap
'Calls Module routine

If Not IsNull([SCEmail]) Then

SendMail Me.cmdSCEMail, SCEmail
Else
MsgBox "Make sure there's a valid email address in the text field " & _
"and that record has been saved", vbExclamation, "EMAIL ADDRESS NEEDED"
End If

ExitErrorTrap:
Exit Sub

ErrorTrap:
LogErrors "cmdSCEmail_Click", Err.Number, Err.Description
MsgBox g_ConstErrorAlert, vbExclamation, "ERROR OCCURRED"
Resume ExitErrorTrap

End Sub




Public Sub SendMail(v_CmdBtn As CommandButton, v_MailAdd As String)
'Takes a text email entry and creates a mail message
On Error GoTo Error_SendMail

If Not IsNull(v_MailAdd) Then

v_CmdBtn.HyperlinkAddress = "MailTo:" & v_MailAdd
Else
MsgBox "There isn't a complete email address for this person", _
vbExclamation, "EMAIL ADDRESS ERROR"

End If

Exit_Error_SendMail:
Exit Sub

Error_SendMail:
LogErrors "Send Mail", Err.Number, Err.Description
Resume Exit_Error_SendMail
End Sub
[/tt]
 
There's so little code in the second routine one might justifiably ask "Why not just put that line in every button routine?"
Answer: Sometimes you just don't see it until you know that everyone can see it! ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top