Delete confirmation button ? (1 Viewer)

Accessator

Registered User.
Local time
Today, 09:20
Joined
Aug 22, 2007
Messages
10
Hi everyone,

I'd like to ask a question in regards to Deletion message.

how to display the warning to user about currently selected row in a continuous form ?

for example:

my mouse is now "clicking" on top of "Item x" textbox, when the user click delete button, how to display in the messageBox something like "Are you sure to delete Item X" Yes / No ?

cheers.:confused:
 

pstephens

Paul S
Local time
Today, 00:20
Joined
Aug 23, 2007
Messages
9
Doesn't Access already do this by default?

Paul S
 

Accessator

Registered User.
Local time
Today, 09:20
Joined
Aug 22, 2007
Messages
10
yes, but doesn't give us what the exact position of our cursor at the moment
eg. when our current mouse cursor is clicking in "Item X", it should says that Item X is about to be deleted.

any idea ?
 

Dom DXecutioner

AWF VIP
Local time
Yesterday, 16:20
Joined
Jun 25, 2007
Messages
57
you really don't need to know the position of the cursor, as this is irrelevant to your purpose. you'll only want to confirm on user action (delete), not when the mouse hoovers over the record.

i would place a delete button on the detail section of the subform, when the user clicks on the delete button to remove the record, access will transfer the focus to that record, if it's not already there.

now you'll need to use the the form's [BeforeDelConfirm] event to notify user and confirm the action...

Code:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
[COLOR="SeaGreen"]'// local variable[/COLOR]
Dim intResponse As Integer
Dim strText As String
    [COLOR="seagreen"]'// get item x info to display[/COLOR]
    'strText = Me.SomeControlValue
    [COLOR="seagreen"]'// suppress default confirmation dialog box[/COLOR]
    Response = acDataErrContinue
    [COLOR="seagreen"]'// display custom dialog box[/COLOR]
    intResponse = MsgBox("Are you sure you wish to delete " & strText & " Item?", vbYesNo + vbQuestion)
    [COLOR="seagreen"]'// if the user changed his/her mind, cancel the delete action[/COLOR]
    If (intResponse = vbNo) Then
        Cancel = True
    End If
End Sub

it's worth mentioning that you may need to suppress an error message that will occur the moment a user cancels the detete action... you could either use [On Error Resume Next] preceding the [DoCmd.RunCommand acCmdDeleteRecord] call on your delete button's [On Click] event

you could also use error trap and ignore error [2501 - The RunCommand action was cancelled]

hope this helps a bit :)
 
Last edited:

Users who are viewing this thread

Top Bottom