Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117

    Emailing a notification on close

    Hello,

    I am setting up a database that will have a form used to provide suggestions.
    It is a relatively simple form only the following fields are applied:
    -Suggestion Name
    -Record Number
    -Suggestion
    -Date Suggested
    -Suggested By [whom]

    Currently the database is set up so that an employee can open it up, the form pops up right away and after they have filled out the form all they have to do is close access.
    ----
    What I would like, is to set up an OnClose event that would send a notification email to the reviewer letting that person know (at a minimum) that a suggestion has been made, and preferably including the record number, suggestion name, and date suggested in the notification email.
    I don't need anything fancy just that it would work. Unfortunately, this is beyond me and the many 'how to automate access to send an email' threads I have found haven't worked for my purposes. Any and all help will be appreciated.


    Thanks in advance!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Check into the SendObject method.

    What exactly have you tried? Was SendObject one attempt? Why did it not work - error message, wrong results, nothing? What exactly don't you understand?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    June7-

    Okay so I actually have it working now, but this has lead me to another question.
    Below is the code I am using to send the email. (This part is now working fine)

    Private Sub notificationemail_Click()

    DoCmd.SendObject acSendNoObject, , , "Staticemailrecipient@mycompany.com", , , "New CI Database Suggestion", "Hello, A new suggestion has been made in the CI Database and is now ready for review. This is an automated message please do not reply. Hal2000 signing off.", False


    End Sub


    However, when this activates I get a popup message which says, "A program is trying to send an email message on your behalf. If this is unexpected, click Deny and verify your antivirus software is up-to-date. For more information about e-mail safety and how you might be able to avoid getting this warning, click Help" It then has an allow, deny, or help button. I need the email to just send without this popup coming up or our employees will be frigging confused when they try to exit and instead get this popup talking about emails.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Not sure what will work. Explore:

    1. each user sets Outlook to allow programmatic access: File > Options > Trust Center > Trust Center Settings > Programmatic Access > make choice
    We have this set to "Warn ..." and don't get warning, maybe because our antivirus software is active and up to date.

    2. use CDO (collaboration data object) for email https://www.accessforums.net/program...ens-43311.html
    Presumes IT does not block.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Try adding this code

    Dim strBody As String
    strBody = strBody & "Hello," & vBCrlf & "A new suggestion has been made in the CI Database and is now ready for review." & vBCrLf & vBCrLf
    strBody = strBody & "Record Number: " !RecordNumber & CHR(9) & !DateSuggested & vBCrLf & vBCrLf
    strBody = strBody & "Suggestion: " !Suggestion & vbCrLf
    strBody = strBody & !Suggestor & vbCrLf & vbCrLf & vbCrLf
    srBody = strBody & "This is an automated message please do not reply." & vBCrLf & Chr(9) & Chr(9) "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT,Staticemailrecipient@mycompany.com", , , "New CI Database Suggestion", strBody, True

    There is additional coding that needs to be done But this will get you the email formatted as:

    To: Staticemailrecipient@mycompany.com

    Subject: New CI Database Suggestion

    Hello,
    A new suggestion has been made in the CI Database and is now ready for review.

    Record Number: #### 6 Nov 2014

    Suggestion: here is where the person is giving the suggestion

    John Q. Public

    This is an automated message please do not reply

    Hal signing off
    Last edited by Thompyt; 11-07-2014 at 03:26 PM. Reason: Beautification

  6. #6
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    Thompyt-

    So I tried the code you provided but when I click the button (I have it attached to an onclick event for testing purposes) I get a syntax error.
    The debugger is highlighting the problem as coming from the below red sections.

    Private Sub SAVESend_Click()


    Dim strBody As String
    strBody = strBody & "Hello," & vbCrLf & "A new suggestion has been made in the CI Database and is now ready for review." & vbCrLf & vbCrLf
    strBody = strBody & "Record Number: " !RecordNumber & CHR(9) & !DateSuggested & vBCrLf & vBCrLf
    strBody = strBody & "Suggestion: " !Suggestion & vbCrLf
    strBody = strBody & !Suggestor & vbCrLf & vbCrLf & vbCrLf
    srBody = strBody & "This is an automated message please do not reply." & vBCrLf & Chr(9) & Chr(9) "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT, "Jmoore@Vermillioninc.com", , , "New CI Database Suggestion", strBody, True


    End Sub

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Missing & for concatenation:

    "Record Number:" &

    "Suggestion:" &

    Chr(9) & "Hal
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Thanks June7,

    Always forgetting something

  9. #9
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    I added the extra "&" but now I am getting a "compile error: Invalid or unqualified reference"
    When the debugger loads it looks like this.
    Private Sub Command235_Click() This line highlighted yellow
    Dim strBody As String
    strBody = strBody & "Hello," & vbCrLf & "A new suggestion has been made in the CI Database and is now ready for review." & vbCrLf & vbCrLf
    strBody = strBody & "Record Number: " & !RecordNumber & Chr(9) & !SuggestedDate & vbCrLf & vbCrLf
    strBody = strBody & "Suggestion: " & !Suggestion & vbCrLf
    strBody = strBody & "This is an automated message please do not reply." & vBCrLf & Chr(9) & Chr(9) & "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT, "Jmoore@Vermillioninc.com", , , "New CI Database Suggestion", strBody, True
    End Sub

    ----
    I'm not sure if it matters, but "!RecordNumber" is highlighted when the debugger loads.
    I have checked the field names against the table and they all match up. So I am not sure where the invalid reference is coming into play.
    Any help would be appreciated as I would really like to be able to include the record #, etc in the email.
    --- Update---
    I tried directly referencing fields using:

    Private Sub Command235_Click()
    Dim strBody As String
    strBody = strBody & "Hello," & vbCrLf & "A new suggestion has been made in the CI Database and is now ready for review." & vbCrLf & vbCrLf
    strBody = strBody & "Record Number: " & Forms!SuggestionForm!RecordNumber & Chr(9) & Forms!SuggestionForm!SuggestedDate & vbCrLf & vbCrLf
    strBody = strBody & "Suggestion: " & Forms!SuggetionForm!Suggestion & vbCrLf
    strBody = strBody & "This is an automated message please do not reply." & vbCrLf & Chr(9) & Chr(9) & "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT, "Jmoore@Vermillioninc.com", , , "New CI Database Suggestion", strBody, True
    End Sub

    However this returns "Run-time error '2450': Continuous Improvement Database cannot find the referenced form 'SuggestionForm'."
    This is confusing me even more because that is the name of the form in question.

    ---Update 2---

    Okay I have taken a new tac based on the boss changing what he wants. New plan is to 'simply' send a pdf of the current form.
    So new code is:

    Private Sub Command235_Click()


    DoCmd.SendObject acSendForm, SuggestionForm, , "Jmoore@Vermillioninc.com", , , "Testing", "Testing 1 2 3", False


    End Sub

    The problem I am having is that while this works...the pdf it creates includes every which utilized this form. I need it to only utilize the current record.
    Any help is greatly appreciated! Thanks

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Need to send PDF of a filtered report, not form.

    Why send pdf if the data can be included in the body of email?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    Quote Originally Posted by June7 View Post
    Need to send PDF of a filtered report, not form.

    Why send pdf if the data can be included in the body of email?
    Because the powers that be are impatient and I still can't get that information to populate in the body of the form.
    See the 1st update on my last post. I keep getting run-time errors saying invalid source and I don't know why. Since the field names are valid. Ugh. I hate access at times. lol Thanks for the continued assistance.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Is this a form/subform arrangement? Is button on main form or subform?

    If button and code behind the form with the data should simply refer to the fields of the form's RecordSource or to textbox name, like:

    Reference to field:
    Me!Suggestion

    Reference to textboxname:
    Me.tbxSuggestion

    If button and code are on main form and data is on subform, like:
    Reference to field:
    Me.subformcontainername!Suggestion

    Reference to textboxname:
    Me.subformcontainername.Form.tbxSuggestion

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    Quote Originally Posted by June7 View Post
    Is this a form/subform arrangement? Is button on main form or subform
    If button and code behind the form with the data should simply refer to the fields of the form's RecordSource or to textbox name, like:
    Reference to field:
    Me!Suggestion
    Reference to textboxname:
    Me.tbxSuggestion
    If button and code are on main form and data is on subform, like:
    Reference to field:
    Me.subformcontainername!Suggestion
    Reference to textboxname:
    Me.subformcontainername.Form.tbxSuggestion
    If you want to provide db for analysis, follow instructions at bottom of my post.
    The button is on the main form.
    There is no subforms whatsoever.
    I just tried the subform arrangement me.subformname!Suggestion, because me!Suggestion wasn't working.

    Based on your information I don't see a reason the below (which was my original setup) doesn't work.

    Private Sub Command235_Click()
    Dim strBody As String
    strBody = strBody & "Hello," & vbCrLf & "A new suggestion has been made in the CI Database and is now ready for review." & vbCrLf & vbCrLf
    strBody = strBody & "Record Number: " & !RecordNumber & Chr(9) & !SuggestedDate & vbCrLf & vbCrLf
    strBody = strBody & "Suggestion: " & !Suggestion & vbCrLf
    strBody = strBody & "This is an automated message please do not reply." & vBCrLf & Chr(9) & Chr(9) & "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT, "Jmoore@Vermillioninc.com", , , "New CI Database Suggestion", strBody, True
    End Sub


    However, this results in "Error Unqualified or invalid reference"

    If i change it to:

    Private Sub Command235_Click()
    Dim strBody As String
    strBody = strBody & "Hello," & vbCrLf & "A new suggestion has been made in the CI Database and is now ready for review." & vbCrLf & vbCrLf
    strBody = strBody & "Record Number: " & Forms!RecordNumber & Chr(9) & Forms!SuggestedDate & vbCrLf & vbCrLf
    strBody = strBody & "Suggestion: " & Forms!Suggestion & vbCrLf
    strBody = strBody & "This is an automated message please do not reply." & vBCrLf & Chr(9) & Chr(9) & "Hal signing off"
    DoCmd.SendObject acSendNoObject, , acFormatTXT, "Jmoore@Vermillioninc.com", , , "New CI Database Suggestion", strBody, True
    End Sub


    This results in "Compile Error: type mismatch."

  14. #14
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    Okay I have attached a sample version of the db for review.
    The button in question is the "SAVE" button on the form "Suggestion Form" (It should load automatically upon opening the DB).

    Thanks again for the assistance.
    Attached Files Attached Files

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Neither of your posted code excerpts have proper references to form controls. If you are going to use the bang (!) or dot (.) must have either the actual form name or the Me alias as shown in my post 12 examples. So either add the Me qualifier with each field reference or use:

    With Me
    'your code
    End With

    Sorry, I did not pick that up earlier.

    Also, your actual field names have spaces in them, which you are not including in your code. Enclose in [].

    ![Record Number]


    Advise not to use spaces or special characters/punctuation (underscore is exception) in naming convention, otherwise must always enclose in [].

    The code works after these edits.

    Be sure to run Debug > Compile after code edits.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  2. Email Notification
    By Ariuser in forum Programming
    Replies: 1
    Last Post: 01-20-2012, 03:44 PM
  3. Popup notification
    By imintrouble in forum Queries
    Replies: 1
    Last Post: 01-19-2012, 03:28 PM
  4. query notification
    By imintrouble in forum Queries
    Replies: 3
    Last Post: 01-18-2012, 10:00 AM
  5. check box notification
    By nichmeg in forum Programming
    Replies: 6
    Last Post: 10-29-2011, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums