Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2003
    Location
    Oxford, England
    Posts
    38

    Unanswered: Ok cancel msgbox prob

    I have a button to delete the current record, but i want a msgbox that says "Are you sure you want to delete this record" Ok, Cancel, which i have manged to do. The only thing is that when i press cancel it deletes the record anyway. Here is the code i have managed to splice together, can anyone see where i have gone wrong?

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2

    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response = vbOK Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    If Response = vbCancel Then
    End If
    End If
    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub

    Thanks in advance,

    Luke

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Ok cancel msgbox prob

    Originally posted by Lukelrc
    I have a button to delete the current record, but i want a msgbox that says "Are you sure you want to delete this record" Ok, Cancel, which i have manged to do. The only thing is that when i press cancel it deletes the record anyway. Here is the code i have managed to splice together, can anyone see where i have gone wrong?

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2

    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response = vbOK Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    If Response = vbCancel Then
    End If
    End If
    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub

    Thanks in advance,

    Luke
    Yes ... Check your conditional ... Try something like:

    If Response <> vbOK Then Exit Sub

    and get rid of the conditional "If Response = vbCancel Then"

  3. #3
    Join Date
    Dec 2003
    Location
    Oxford, England
    Posts
    38
    thanks,

    Ive made the change you suggested, but still when i press cancel it deletes the record. What i forgot to mention before is that once you press either ok or cancel you get another mesgbox which is blank with just an OK. Im not sure if that is significant? My code now looks like this:

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2



    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response = vbOK Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    If Response <> vbOK Then Exit Sub

    End If
    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by Lukelrc
    thanks,

    Ive made the change you suggested, but still when i press cancel it deletes the record. What i forgot to mention before is that once you press either ok or cancel you get another mesgbox which is blank with just an OK. Im not sure if that is significant? My code now looks like this:

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2



    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response = vbOK Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    If Response <> vbOK Then Exit Sub

    End If
    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub
    Oh my ... Ok. I can't believe that I'm stooping this low ... Do this: Replace the code to look like this:

    ...
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response <> vbOK Then Exit Sub
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    ...

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you have quite a mess there! try this:



    Dim Message As String


    on error goto Err_Command1917_Click

    Message = "You are about to permanently delete this project",
    if MsgBox(Message, vbokcancel, "Are you sure?") = vbcancel then exit sub
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70



    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub


    Later: "mess" was not aimed at you M Owen!!
    Last edited by izyrider; 03-24-04 at 11:38.
    currently using SS 2008R2

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by izyrider
    you have quite a mess there! try this:



    Dim Message As String


    on error goto Err_Command1917_Click

    Message = "You are about to permanently delete this project",
    if MsgBox(Message, vbokcancel, "Are you sure?") = vbcancel then exit sub
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70



    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub
    Izy,

    You're too generous ...

  7. #7
    Join Date
    Dec 2003
    Location
    Oxford, England
    Posts
    38
    It still does exactly the same, i press cancel, a blank msgbox pops up and i hit OK and the record is still deleted.

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2

    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response <> vbOK Then Exit Sub
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by Lukelrc
    It still does exactly the same, i press cancel, a blank msgbox pops up and i hit OK and the record is still deleted.

    Private Sub Command1917_Click()
    On Error GoTo Err_Command1917_Click

    Dim Response As Integer
    Dim Message As String
    Dim ButtonsAndIcons As Integer
    Dim TITLE As String
    Dim vbOK: vbOK = 1
    Dim vbCancel: vbCancel = 2

    MsgBox "You are about to permanently delete this project", 1, "Delete Project"
    Response = MsgBox(Message, ButtonsAndIcons, TITLE)
    If Response <> vbOK Then Exit Sub
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


    Exit_Command1917_Click:
    Exit Sub

    Err_Command1917_Click:
    MsgBox Err.Description
    Resume Exit_Command1917_Click
    End Sub
    Ah .... You have the wrong msgbox parameter ...

    Example: (My Code)
    Code:
        Dim MsgVal As VbMsgBoxResult
        
        MsgVal = MsgBox("Are you absolutely certain that you want to void this purchase order?", vbOkCancel, "System Monitor")
        If MsgVal <> vbOK Then Exit Sub

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Lukelrc: please delete your code - it is a tragedy!

    buttonsandicons is undefined
    message is undefined
    title is undefined

    dim vbok is a bizarre and foolish thing to attempt, and why would you want to dim a var just to set it to a perfectly serviceable intrinsic constant?

    dim vbcancel: ditto



    use my code: it is complete and it works (assuming you got the menu stuff correct - i didn't check it)

    use M Owen's suggestions if you want to build the code yourself.

    but please, delete what you have at the moment. it's going nowhere.

    izy
    currently using SS 2008R2

  10. #10
    Join Date
    Dec 2003
    Location
    Oxford, England
    Posts
    38
    haha!

    can u tell i don't know what i'm doing?

    Right i have put in your code Izy, but this line is hilted red and it wont work.

    Message = "You are about to permanently delete this project",

  11. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    get rid of that trailing comma

    izy
    currently using SS 2008R2

  12. #12
    Join Date
    Dec 2003
    Location
    Oxford, England
    Posts
    38
    Brill!! It works! Thanks.

  13. #13
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    phew!

    (and sorry about the "," that shouldn't have been there)

    izy
    currently using SS 2008R2

Posting Permissions

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