Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete custom dialog problem... 1

Status
Not open for further replies.

sagamw

Technical User
Nov 11, 2009
104
GR
I have this routine for custum dialog box that works fine ONLY when I "remarked" everything after the Response = acDataErrContinue in the if statement.

I am just trying to have a "Record Deleted" dialog and close the form and open my search form.

If I enable the 3 lines (or just the 2 close/open lines) the record doesn't deleted.

Code:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, _
    Response As Integer)
    Dim strMessage As String
    Dim intResponse As Integer
    
    On Error Resume Next
    
    ' Display the custom dialog box.
    strMessage = "blah-blah" & vbNewLine & _
    "blah-blah" & vbNewLine & vbNewLine & _
    "blah-blah"
    intResponse = MsgBox(strMessage, vbYesNo + _
        vbQuestion, _
        "blah-blah")
    
    ' Check the response.
    If intResponse = vbYes Then
        Response = acDataErrContinue
        'MsgBox "Record Deleted", , "blah-blah"
        'DoCmd.Close
        'DoCmd.OpenForm "Search form"
    Else
        Cancel = True
    End If
    
End Sub


 
You are not going to be able to close the current form during that formes Before 'anything' event.

Instead you can declare a variable with module/global scope and set it. On the after 'anything' event then you do what you can't do in the before event.
 
How are ya sagamw . . .

[blue]lameid[/blue] is correct, however said another way ... [blue]you can't close the form until the [blue]AfterDeleteConfirm[/blue] event occurs. Note: [purple]this event occurs wether you cancel or not![/purple] The good thing about [blue]AfterDeleteConfirm[/blue] is that you can reconfirm your selection using the [blue]Status[/blue] argument. So change your [blue]BeforeDeleteConfirm[/blue] event to:
Code:
[blue]   Dim Msg As String
    
   Msg = "blah-blah" & vbNewLine & _
         "blah-blah" & vbNewLine & vbNewLine & _
         "blah-blah"
   
   If MsgBox(Msg, vbYesNo + vbQuestion, "blah-blah") = vbYes Then
      Response = acDataErrContinue
   Else
      Cancel = True
   End If[/blue]
The [blue]AfterDeleteConfirm[/blue] event should look like:
Code:
[blue]Private Sub Form_AfterDelConfirm(Status As Integer)
   If Status = acDeleteOK Then
      MsgBox "Record Deleted", , "blah-blah"
      DoCmd.Close
      DoCmd.OpenForm "Search form"
   End If

End Sub[/blue]

Thats it! Perform your testing.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you both,
and TheAceMan1 here's a star for your code.

This is the first db I develop and I haven't noticed the AfterDelConfirm event.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top