?
Solved

Trying to add a msgbox with 'yes or no' buttons before delete record?

Posted on 2003-02-20
8
Medium Priority
?
271 Views
Last Modified: 2008-02-01
Hi,

I'm trying to add a msgbox with 'yes or no' buttons before the delete process removes a record?

I have been playing around with macros a bit but don't have much to go on.

Any help would be appreciated,

Mars
(a bit of a newbie)
0
Comment
Question by:marsbar105
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 

Expert Comment

by:helixcon
ID: 7989394
Try this

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
       If MsgBox("Confirm deletion", 1) = vbOK Then
            Response = False
            Cancel = False
        Else
            Cancel = True
            Response = False
       
         End If
End Sub


Please note that on the Tools,Options,EditFind,Confirm,Record Changes must be turned on as the BeforeDelConfirm is triggered before the default message is displayed. Paste this on the form (or subform) you are working on
0
 
LVL 28

Expert Comment

by:TextReport
ID: 7989584
For the Message Box to use Yes No buttons the you can change the example above to read

If MsgBox("Confirm deletion", vbYesNo) = vbYes Then

Cheers, Andrew
0
 
LVL 2

Expert Comment

by:ACSPanama
ID: 7989622
Here is the VB Code for Yes, No, Cancel Mesage Box...Modify it to suit your needs.If you don't want Canel Option Change "vbYesNoCancel" to "vbYesNo"...ACSPanama


'(MssBox Yes, No, Cancel)
    If IsNull([Combo14]) = False Or Me![SubTotal] = 0 Then
        Dim Msg, Style, Title, Help, Ctxt, Response, MyString
        Msg = "Update This Customers Information." & Chr$(10) & Chr$(13) & "Add a New Customer to the Customer Database."  
        Style = vbYesNoCancel + vbInformation + vbDefaultButton1   ' Define buttons.
        Title = "Update This Customer  or  Add a New Customer"    ' Define title.
        Response = MsgBox(Msg, Style, Title, Help, Ctxt)
        If Response = vbYes Then GoTo Skip1   ' User choose Yes.
        MyString = "Yes"    ' Perform some action.
        If Response = vbNo Then GoTo Skip0
        MyString = "No"    ' Perform some action.
        If Response = vbCancel Then GoTo ByeBye
        MyString = "Cancel"
        End If
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:marsbar105
ID: 7989682
Everyone,

Where do I put this code, and am I still using the macro for msgbox??

Here is some detail: This whole thing is for a "delete asset" button on a form.

Thanks,
Mars
0
 

Expert Comment

by:dpleslie
ID: 7995324
Here is another alternative:

Dim confirm As Integer
confirm = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Confirm Delete")
If confirm = 6 Then 'User clicked Yes
  DoCmd.SetWarnings False 'prevent a second confirm message
  DoCmd.RunCommand acCmdDeleteRecord
  DoCmd.SetWarnings True
End If

Whether you use this code or someone else's suggestion, it should be tied to the OnClick event of the button.

In design view, right click the button and select "Properties". Under the "Events" tab, find "OnClick" and select "[Event Procedure]" from the drop-down list (Combo Box) to the right. Then, click the "..." button to the right to open the VB editor and paste the code in there.
0
 

Expert Comment

by:helixcon
ID: 7996290
paste the following code on the "on click" event of the button you are using to erase the record:

       Me.AllowDeletions = True
            DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
            DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
        Me.AllowDeletions = False

This will allow you to delete the record in case the record set is blocked to avoid manual deletions. Then just copy and paste the code listed on my previous comment right below (or before) the erase button sub (after the End Sub of the On Click event for the button in question).
The msgbox comand is inserted wherever you need the macro to stop and give you the confirm question

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
 etc....
End Sub
this is triggered when the default access delete confirmation is given.

0
 
LVL 2

Accepted Solution

by:
ACSPanama earned 140 total points
ID: 7999180
Make A button on your form which sayes "Delete Asset"
on the "on click" event for your button paste this VB Code.

On Error GoTo ByeBye
        Dim Msg, Style, Title, Help, Ctxt, Response, MyString
        Msg = "Are You Sure You Want To" & Chr$(10) & Chr$(13) & "Delete this Asset?"   ' Define message.
        Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
        Title = "Delete Asset?"    ' Define title.
        Response = MsgBox(Msg, Style, Title, Help, Ctxt)
        If Response = vbYes Then    ' User choose Yes.
        GoTo Skip0
        MyString = "Yes"    ' Perform some action.
        Else:
        GoTo ByeBye ' User cho0se No.
        MyString = "No"    ' Perform some action.
        End If
Skip0:
    Me.AllowDeletions = True
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    Me.AllowDeletions = False
ByeBye:
0
 

Author Comment

by:marsbar105
ID: 8008269
Thank you very much everyone.  All very good answers.

Mars
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question