Results 1 to 6 of 6
  1. #1
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90

    Yes No Cancel MsgBox

    I need a good web page recommendation to help me set up a 3-button message box so when the user closes a form they just edited it will ask them "Do you want to add these records?" Yes, No, Cancel.



    Yes - adds the records, NO - returns them to the edit form, or Cancel - closes the edit form and returns them to the main form.

    The following is as close as I can cobble together (borrowed from an internet site) because I do not understand code enough to go further. No matter which of my button is selected the records still get added.

    Any and all help would be appreciated.

    Private Sub Form_Close()

    MessageBox
    End Sub

    Public Sub MessageBox()


    Dim intAnswer As Integer
    intAnswer = MsgBox("Are you sure you want to add/update these parts?", vbQuestion + vbYesNoCancel, "Confirm")

    Select Case intAnswer
    Case vbYes
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Q_AppendPNECNfromRelationMaster"
    DoCmd.SetWarnings True

    Case vbNo
    MsgBox "Your decided NOT to update your records"
    ??? not sure what to put here

    Case vbCancel
    ??? not sure what to put here

    End Select
    End Sub

  2. #2
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Hi Rick,

    Try the below instead.

    Code:
    Dim strAnswer As String 'Change This
    strAnswer = MsgBox("Are you sure you want to add/update these parts?", vbQuestion + vbYesNoCancel, "Confirm")
    Select Case intAnswer
    Case vbYes
    'Use this do not turn the system warnings off
     CurrentDb.Execute "Q_AppendPNECNfromRelationMaster"
    Case vbNo
        MsgBox "Your decided NOT to update your records"
    Case vbCancel
        'Do something if they select cancel
    End Select
    You're giving the user 3 options with this and you will carry-out the appropriate action for the selection they make. Also, never use "Docmd.SetWarnings False". If the code gets interuppted before it gets to the line to turn them back on then the system warnings will be turned off and the user will not be prompted when doing things such as deleting records.

    Dan
    Access Development

    Quote Originally Posted by Rick West View Post
    I need a good web page recommendation to help me set up a 3-button message box so when the user closes a form they just edited it will ask them "Do you want to add these records?" Yes, No, Cancel.

    Yes - adds the records, NO - returns them to the edit form, or Cancel - closes the edit form and returns them to the main form.

    The following is as close as I can cobble together (borrowed from an internet site) because I do not understand code enough to go further. No matter which of my button is selected the records still get added.

    Any and all help would be appreciated.

    Private Sub Form_Close()

    MessageBox
    End Sub

    Public Sub MessageBox()


    Dim intAnswer As Integer
    intAnswer = MsgBox("Are you sure you want to add/update these parts?", vbQuestion + vbYesNoCancel, "Confirm")

    Select Case intAnswer
    Case vbYes
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Q_AppendPNECNfromRelationMaster"
    DoCmd.SetWarnings True

    Case vbNo
    MsgBox "Your decided NOT to update your records"
    ??? not sure what to put here

    Case vbCancel
    ??? not sure what to put here

    End Select
    End Sub

  3. #3
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    Tried your fix. Got the 3-button msgbox to appear but the 3 buttons do not work quite the way I want them too yet due to I don't really know what to put under each buttons case.

    Here is what I want it to do:

    On my main form "F_Parent" they click a button if they want to add a record. That button opens "F_PartAdds" where they add new part data, then "On Close" event of "F_PartAdds" I want a 3-button msg box to appear and work as follows:

    Yes - run the query "Q_AppendPNECNfromRelationMaster" (this appears to work)

    No - close 3-button msgbox, close form "F_PartAdds" and return to form "F_Parent" (does not open the msgbox in the code but works exactly like I picked the "Yes" option - strange)

    Cancel - close msg box and leave "F_PartAdds" open for further use.

  4. #4
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    It should work exactly like your web page msgbox, when I push that I want to log out I get a 2-button msgbox asking if I want to log out "Yes" or "Cancel".

    If I choose Cancel it returns me to the page just behind the msg box.

  5. #5
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    First question that I have to ask is why do you need this? It sounds like you're just adding records. To answer your question though, you would have it something like this.

    [CODE]Dim strAnswer As String 'Change This
    strAnswer = MsgBox("Are you sure you want to add/update these parts?", vbQuestion + vbYesNoCancel, "Confirm")
    Select Case intAnswer
    Case vbYes 'Run the query
    CurrentDb.Execute "Q_AppendPNECNfromRelationMaster"
    Case vbNo 'Close the form and exit
    Docmd.Close acForm,"F_PartAdds"
    Exit Sub
    Case vbCancel 'Exit sub but keep form open
    Exit Sub
    End Select[/CODE]

    Dan
    Access Development




    Quote Originally Posted by Rick West View Post
    It should work exactly like your web page msgbox, when I push that I want to log out I get a 2-button msgbox asking if I want to log out "Yes" or "Cancel".

    If I choose Cancel it returns me to the page just behind the msg box.

  6. #6
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Lets try this again with the code. It didn't wrap the fist time.

    Code:
    Dim strAnswer As String 'Change This
    strAnswer = MsgBox("Are you sure you want to add/update these parts?", vbQuestion + vbYesNoCancel, "Confirm")
    Select Case intAnswer
    Case vbYes 'Run the query
       CurrentDb.Execute "Q_AppendPNECNfromRelationMaster"
    Case vbNo 'Close the form and exit
         Docmd.Close acForm,"F_PartAdds"
              Exit Sub
    Case vbCancel 'Exit sub but keep form open
                Exit Sub
    End Select

    Quote Originally Posted by Rick West View Post
    It should work exactly like your web page msgbox, when I push that I want to log out I get a 2-button msgbox asking if I want to log out "Yes" or "Cancel".

    If I choose Cancel it returns me to the page just behind the msg box.

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

Similar Threads

  1. MsgBox strange/missing icon
    By AndrewAfresh in forum Access
    Replies: 6
    Last Post: 11-11-2009, 10:16 AM
  2. Cancel listbox selection
    By vba-dev in forum Access
    Replies: 0
    Last Post: 10-26-2009, 12:18 PM
  3. Alterations to MsgBox command
    By Robert M in forum Programming
    Replies: 4
    Last Post: 06-30-2009, 02:14 PM
  4. Replies: 4
    Last Post: 04-01-2009, 11:48 AM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 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