Results 1 to 11 of 11
  1. #1
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117

    Message Box

    Hi guys, I have a submit button that sends an email. The email gets send automatically based on the combo box value the user choses, which is who to send the email too. I would like this button that gives a message box instead of an error that warns the person to select the user so when they press submit they don't get an error but if they fill it out they don't get no message box, it just sends the email. Thanks!

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Are you using VBA? if so please paste the code.

  3. #3
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    Yes im using vba, I don't have any code of the message box but for the email, do you want me post the code for the email?

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Yes please. All the code associated with the button.

  5. #5
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    Private Sub cmdSendEmail_Click()



    Dim Subject As String
    Dim Body As String
    Dim Email As String
    Subject = "Test Request Approval"
    Body = ""
    Body = Body & "GTSR ID: " & GTSR_TR_ID.Value & vbNewLine & vbNewLine
    Body = Body & "TR ID: " & TR_ID.Value & vbNewLine & vbNewLine
    Body = Body & "Revision Test Request is on (starts at 0): " & Revisions.Value & vbNewLine & vbNewLine
    Body = Body & "Test Title: " & Test_Title.Value & vbNewLine & vbNewLine
    Body = Body & "Requestor's Name: " & cbofirst_name.Value & " " & cbolast_name.Value & vbNewLine & vbNewLine
    Body = Body & "Requestor Clock #: " & cboclock.Value & vbNewLine & vbNewLine
    Body = Body & "A/C Model: " & Combo58.Value & vbNewLine & vbNewLine
    Body = Body & "This email was auto-generated!"
    Email = GetApproverEmailFromName(Me.cboApprover)
    DoCmd.SendObject acSendNoObject, "", "", Email, , , Subject, Body, True
    DoCmd.Close acForm, "TR_Form"
    DoCmd.Close acForm, "GTSR_ID_For_TR_Form", acSaveYes

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Code:
    Private Sub cmdSendEmail_Click()
    
     Dim Subject As String
     Dim Body As String
     Dim Email As String
    
    If IsNull(Me.cboApprover) Then
    
    MsgBox "This is fun"
    
    exit sub
    
    else 
    
    Subject = "Test Request Approval"
     Body = ""
     Body = Body & "GTSR ID: " & GTSR_TR_ID.Value & vbNewLine & vbNewLine
     Body = Body & "TR ID: " & TR_ID.Value & vbNewLine & vbNewLine
     Body = Body & "Revision Test Request is on (starts at 0): " & Revisions.Value & vbNewLine & vbNewLine
     Body = Body & "Test Title: " & Test_Title.Value & vbNewLine & vbNewLine
     Body = Body & "Requestor's Name: " & cbofirst_name.Value & " " & cbolast_name.Value & vbNewLine & vbNewLine
     Body = Body & "Requestor Clock #: " & cboclock.Value & vbNewLine & vbNewLine
     Body = Body & "A/C Model: " & Combo58.Value & vbNewLine & vbNewLine
     Body = Body & "This email was auto-generated!"
     Email = GetApproverEmailFromName(Me.cboApprover)
     DoCmd.SendObject acSendNoObject, "", "", Email, , , Subject, Body, True
     DoCmd.Close acForm, "TR_Form"
     DoCmd.Close acForm, "GTSR_ID_For_TR_Form", acSaveYes
    
    end sub
    Hopefully this works, Let us know what line an error occurs if it does.

  7. #7
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    no message box comes up it goes straight to the email

  8. #8
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    nvm it worked thanks!

  9. #9
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    it worked then stopped working, ill post my code

  10. #10
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    It works but it doesn't work on the first record which is problem because if somebody does a filter search on a form to edit it and they forget to do it it won't work idk why. thanks!

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The code in Post #6 is missing a line: "End If".

    Maybe try this:
    Code:
    Private Sub cmdSendEmail_Click()
    
        Dim Subject As String
        Dim Body As String
        Dim Email As String
    
        '    If IsNull(Me.cboApprover) Then
        If Len(Trim(Me.cboApprover)) = 0 Then   '<- Me.cboApprover could have an empty string and not a NULL
            MsgBox "This is fun"
            Exit Sub
        End If
    
        Subject = "Test Request Approval"
        Body = ""
        Body = Body & "GTSR ID: " & GTSR_TR_ID.Value & vbNewLine & vbNewLine
        Body = Body & "TR ID: " & TR_ID.Value & vbNewLine & vbNewLine
        Body = Body & "Revision Test Request is on (starts at 0): " & Revisions.Value & vbNewLine & vbNewLine
        Body = Body & "Test Title: " & Test_Title.Value & vbNewLine & vbNewLine
        Body = Body & "Requestor's Name: " & cbofirst_name.Value & " " & cbolast_name.Value & vbNewLine & vbNewLine
        Body = Body & "Requestor Clock #: " & cboclock.Value & vbNewLine & vbNewLine
        Body = Body & "A/C Model: " & Combo58.Value & vbNewLine & vbNewLine
        Body = Body & "This email was auto-generated!"
        Email = GetApproverEmailFromName(Me.cboApprover)
        DoCmd.SendObject acSendNoObject, "", "", Email, , , Subject, Body, True
        DoCmd.Close acForm, "TR_Form"
        DoCmd.Close acForm, "GTSR_ID_For_TR_Form", acSaveYes
    End Sub

    Just curious:
    Why are you using a function to get the value from "Me.cboApprover", instead of just getting the value from the combo box?
    Code:
     Email = GetApproverEmailFromName(Me.cboApprover)
    What is the code for the function?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  2. Replies: 2
    Last Post: 01-23-2014, 12:40 PM
  3. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  4. Replies: 9
    Last Post: 09-26-2012, 12:20 PM
  5. Help with message box
    By Cablenm in forum Access
    Replies: 9
    Last Post: 10-14-2011, 05:06 PM

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