Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jul 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, Can anyone help me?... I'm trying to create a form that submits a bunch of data and then emails a specific email account each time a user clicks a button. The program works great but if the user closes out of the email (brought up in Outlook) the program fails and goes to the debugger. Is there a way to tell if the program is sent so that I can delete the information that was entered and cancel without the program stalling out?

    This is the code I'm using to bring up the email in outlook. I need the editmessage property to be true in case other information needs to be added.


    DoCmd.SendObject To:="guy@website.com", Subject:="New Rework ", _
    MessageText:=strEmailBody, EditMessage:=True


    Thanks in advance!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You need to create an error handler:

    Code:
    Private Sub cmdSendMessage_Click()
      On Error GoTo ErrHandler
      ...
      DoCmd.SendObject To:="guy@website.com", Subject:="New Rework ", _
    	MessageText:=strEmailBody, EditMessage:=True
      ...
      Exit Sub
    
    ErrHandler:
      If Err = 2501 Then
    	' User canceled the e-mail
    	...
      Else
    	' A real error occurred
    	MsgBox Err.Description, vbExclamation
      End If
    End Sub

  3. #3
    New Lounger
    Join Date
    Jul 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787006' date='31-Jul-2009 16:25']You need to create an error handler:

    Code:
    Private Sub cmdSendMessage_Click()
      On Error GoTo ErrHandler
      ...
      DoCmd.SendObject To:="guy@website.com", Subject:="New Rework ", _
    	MessageText:=strEmailBody, EditMessage:=True
      ...
      Exit Sub
    
    ErrHandler:
      If Err = 2501 Then
    	' User canceled the e-mail
    	...
      Else
    	' A real error occurred
    	MsgBox Err.Description, vbExclamation
      End If
    End Sub
    [/quote]




    It works! Thanks Hans!

  4. #4
    New Lounger
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='scarste' post='787019' date='31-Jul-2009 17:39']It works! Thanks Hans![/quote]


    Hans,

    Would you be able to provide the remainder of the code to email the form - we have a time sheet db and would like to submit leave request via email.

    Thanks,
    Sam

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Can you provide more detailed information about what you want to accomplish?

  6. #6
    New Lounger
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787399' date='03-Aug-2009 21:35']Can you provide more detailed information about what you want to accomplish?[/quote]

    Have a form[opm71] titled: Request for Leave or Approved Absence.

    we (employees) would like to have this form emailed to our supervisor once completed so that is will be Approved or Disapproved by email.
    the form is Single Form and is able to have multiple records so the code would have to send current record only.

    the department has 5 branch offices so the code would need to identify the supervisor by the employees office symbol.

    Sam

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    An Access form isn't really suitable for sending by e-mail.

    The relatively easiest solution is probably to compose the text of the e-mail message using the data from the current record on the form.

    If you have a table with details about the branch offices, you can look up the name and e-mail address of the supervisor in this table and use it for the e-mail.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •