Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exit Confirmation (2000)

    How can I set up a procedure to get confirmation before the exit button is selected?
    In vb.net I can say:
    dim dlgResult as DialogResult
    dlgResult = messagebox.show("Capton","Title",.....
    if dlgResult = dialogResult.Yes then
    me.close()
    end if.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Exit Confirmation (2000)

    In VBA, MsgBox is a function, not an object. You can use it like this:

    If Case MsgBox("Do you want to exit?", vbQuestion + vbYesNo) = vbYes Then
    ...
    Else
    ...
    End If

    But which Exit button do you mean?

  3. #3
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exit Confirmation (2000)

    I have a button called btnExit on a form and I want to get confirmation before exiting.

  4. #4
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exit Confirmation (2000)

    I am not sure what the Case does, but it gave me a syntax error and it works without it.
    Now I have an OK button that I want to check to see if a text box has a value, if it does open frmCalendar. If it is empty, give them a message and return focus to the text box.
    Here is what I have thus far:
    Private Sub btnOK_Click()
    If txtEmpName.Text <> "" Then
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmCalendar"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Else
    MsgBox("Please select your name", vbOKOnly) = vbOK

    End If


    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Exit Confirmation (2000)

    OK, in that case you can use something like this:

    Private Sub btnExit_Click()
    If MsgBox("Do you want to close this form?", vbQuestion + vbYesNo) = vbYes Then
    DoCmd.Close
    End If
    End Sub

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Exit Confirmation (2000)

    I'm sorry, the Case didn't belong there; I have removed it from my reply.

    Notes:

    1. Instead of

    If txtEmpName.Text <> "" Then

    use

    If Not IsNull(Me.txtEmpName) Then

    You can only refer to the Text property of a text box in Access if it has the focus.

    2. You cannot use

    MsgBox("Please select your name", vbOKOnly) = vbOK

    If you only want to display a message box, use

    MsgBox "Please select your name"

    Since you don't need the return value, you can call MsgBox as a procedure here, instead of as a function. So the code becomes

    Private Sub btnOK_Click()
    If Not IsNull(Me.txtEmpName) Then
    DoCmd.OpenForm "frmCalendar"
    Else
    MsgBox "Please enter your name."
    End If
    End Sub

Posting Permissions

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