Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    104

    Unanswered: Dialog Boxes? How to? [VBA MS Access 2002]

    Hi All,
    I was just wondering how dialog boxes can be put to use in VBA (Microsoft Access 2002).

    I have a form which has a "delete user" button on it. I want a dialog box to pop up saying something like "You are about to delete a user, are you sure you want to do this? Yes/No"

    Can anyone help?

    PS: I serached the MS Access DB forum here and I found nothing that pertains to this

  2. #2
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238

    Re: Dialog Boxes? How to? [VBA MS Access 2002]

    Originally posted by shassouneh
    Hi All,
    I was just wondering how dialog boxes can be put to use in VBA (Microsoft Access 2002).

    I have a form which has a "delete user" button on it. I want a dialog box to pop up saying something like "You are about to delete a user, are you sure you want to do this? Yes/No"

    Can anyone help?

    PS: I serached the MS Access DB forum here and I found nothing that pertains to this
    A dialog box is created with the MsgBox command and can be used in one of 2 ways. The first way is just as an information or warning dialog box. You would use syntax such as:

    MsgBox "This is the message", vbInformation,"This is the Dialog Caption"

    Or you can use it to ask a question and have the result returned to you to do something with it like this:

    If MsgBox("You are about to delete a user, are you sure you want to do this? Yes/No", vbQuestion + vbYesNo,"Delete User?") = vbYes Then
    ' do something to delete the user
    End If

  3. #3
    Join Date
    Nov 2003
    Posts
    104
    justin_tighe,
    You beat me to replying. I figured it out. A little bit of sniffing around on MSDn can prove useful.
    For future refference, here is what I did (for anyone who has the same question as I did)

    Code:
    Dim msg As String
        Dim result As VbMsgBoxResult
        
        msg = "You Are About to delete the user: " & txtUserName.Value & " from the system permenantly. Are you sure you want to do this? NOTE: this Operation CANNOT be undone!"
        result = MsgBox(msg, VbMsgBoxStyle.vbYesNoCancel, "Are you Sure?")
        
        If (result = vbYes) Then 'if and only if the user clicks on Yes
        
            DoCmd.RunSQL (Users_del) 'perform the deletion from the uses table
            DoCmd.RunSQL (Intersection_del) 'perform the deletion from the Intersection table
            
        End If
        
        ElseIf (result = vbNo) Then 'if the user decided to not delete
        
            msg = "Deletion of User: " & txtUserName.Value & " Has Been Aborted!"
            Call UpdateStatusBar(msg)
        End If
        
        Else 'the user clicked cancel
        
            msg = "Deletion of User: " & txtUserName.Value & " Has Been Cancelled!"
            Call UpdateStatusBar(msg)
        End If

    NOTE: [i]I plan on releasing the MDB file (with the VBA source code) when i am done as Open Source. I realize such a program can be useful to others as they see my code

  4. #4
    Join Date
    Jun 2013
    Posts
    2
    There is a tutorial that shows step by step how to create a simple message box with a button. This is the url: Using an Access Button to Create a Message Box - VBA Digital Reins
    Hope that helps. I tried to make it step by step.

Posting Permissions

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