Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call a function from Before Del Confirm event? (2000)

    Is there any way to call a function from the Before Delete Confirm and After Delete Confirm events of a form using the standard arguments, for example,
    BeforeDelConfirm: =SuppressDelConfirm(Cancel, Response)
    or can you only use event procedures with these events?

    The is the function (in a standard module) mentioned above:

    Function SuppressDelConfirm(Cancel As Integer, Response As Integer)
    Dim frm As Form
    Set frm = Screen.ActiveForm
    Response = acDataErrContinue
    ' Display custom dialog box.
    If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
    Cancel = True
    End If
    End Function

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

    Re: Call a function from Before Del Confirm event? (2000)

    Problem is that Cancel and Response are both arguments that can be modified in the BeforeDelConfirm event handler. There is no good way to pass the arguments as provided in the event procedure when you set the event to =Function(...)

    But you can create a general event handler in the form module or even in a general module:

    Public Sub BeforeDelConfirmHandler(MyCancel As Integer, MyResponse As Integer)
    ' Suppress default Confirm Delete dialog box.
    MyResponse = acDataErrContinue
    ' Display custom dialog box.
    If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
    MyCancel = True
    End If
    End Sub

    You still have to create an event procedure, but you only need one line to call the general handler and pass the arguments:

    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
    BeforeDelConfirmHandler Cancel, Response
    End Sub

    This will work since arguments are passed by reference in VBA unless explicitly specified as by value.

Posting Permissions

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