Submit Button That Emails Message

  • Thread starter Thread starter scott04
  • Start date Start date
S

scott04

Hi everyone,
I am trying to have a button that onclick basically blanks out my form and
in turn outlook sends an email notification that a new record has been
created. One problem though when the user doesn't fill out the entire form
and my coded rules kick in to make a user fill in a field my email code still
fires. Can someone look at my code below and make some suggestions so the
email code doesn't fire unless no errors? Thanks

Private Sub Sub_Question_Click()
On Error GoTo Procerror
DoCmd.GoToRecord , , acNewRec
Dim strPath As String
Dim rst As DAO.Recordset
Dim AppOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set AppOutLook = CreateObject("Outlook.Application")
Set MailOutLook = AppOutLook.CreateItem(olMailItem)
Dim EContent As String
Dim stDocName As String
Me.Dirty = False
With MailOutLook
..To = "(e-mail address removed)"
..CC = "(e-mail address removed)"
..Subject = "Pending Request"
..Importance = olImportanceHigh
..Body = "You have a new ticket in the database"
..Save
..Send
End With
Procerror:
If Err.Number = 20 Or Err.Number = 0 Or Err.Number = 2105 Then
Resume Next
Else
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in Click event procedure..."
 
Scott,

Your me.dirty line should force that form to save. Where do you have the
code that checks to make sure your rules have been followed? I would
normally put them in the forms BeforeUpdate event, and would set the Cancel
parameter to True if a condition is violated.

Although I have not tried this, I believe setting Cancel to True in the
BeforeUpdate event will cause the Me.Dirty = False line to throw an error.
If that is the case, then the following would

so try something like:

On Error Resume Next
Me.Dirty = False
if err.number <> 0 then Exit Sub
On Error goto ProcError
With MailOutlook

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
Dale worked great thank you so much...i was really scratching my head trying
to figure it out. Thank again!
 
BTW,

Does this method get around the security message when you send the email?

If not, then you could save yourself a lot of code and use the SendObject
method.


--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
Back
Top