Programming a yes/no message box...

mjohnson629

New member
Local time
Yesterday, 18:41
Joined
Mar 24, 2006
Messages
8
Hey, I have a message box that I am needing to program. It is a yes/no message box. Here is the vb code so far.

Private Sub btnSemester_Click()
RetValue = MsgBox("Are you sure?", vbYesNo, "Confirmation")
End Sub


I need to program this so that when the user clicks yes it will clear all the data in the DB. (I know this isn't really smart, but it is what the project sponsor wants.) Any help would be greatly appreciated...

Matt Johnson
 
Hi mjohnson629,

Check this code or take a look at the attached as well;

Code:
Private Sub CmdCleartblDetails_Click()

    'Delete tblDetails properties
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Do you want to continue with deleting all records in tblDetails ?"    ' Define message.
    Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
    Title = "Delete Records in tblDetails"    'Define title.
    Ctxt = 1000    ' Define topic
            ' context.
            ' Display message.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)

    'turn warnings from table deletion off
    DoCmd.SetWarnings False


    If Response = vbYes Then    ' User chose Yes.
        '    MyString = "Yes"    ' Perform some action.
        DoCmd.RunSQL "DELETE * FROM tblDetails"
        MsgBox "All Records have been deleted from tblDetails"

    Else    ' User chose No.
        MyString = "No"    ' Perform some action.
        MsgBox "No Records have been deleted from tblDetails"
    
    End If

    'This turns the warnings back on in case needed elsewhere
    DoCmd.SetWarnings True
    
End Sub

Hope this helps?:p

Robert88
 

Attachments

Users who are viewing this thread

Back
Top Bottom