Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Unanswered: Warnings when deleting a record

    When working with tables I mostly use the
    DoCmd.SetWarnings(False) - statement for ignoring the Access-messages so I can display my own messages if necessary.

    I have 2 linked tables.
    'On delete cascade' is activated.

    When I want to delete a record which has links to the other table it can not be deleted.
    So far so good, but instead of Access showing its warnings I want to display a message myself.
    Is there anything I can use to intercept this?

    Thanks

  2. #2
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    >I have 2 linked tables.
    >'On delete cascade' is activated.

    >When I want to delete a record which has links to the other table it can >not be deleted.


    If 'On delete cascade' is activated or checked it should allow for cascading deletion of records. Confused????

    Anyway - try to trap for error number 3200 as in the example below:


    Private Sub cmdDelete_Click()
    On Error GoTo Err_cmdDelete_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Exit_cmdDelete_Click:
    Exit Sub

    Err_cmdDelete_Click:
    If Err.Number = 3200 Then
    MsgBox "Custom Message"
    Else
    MsgBox Err.Description
    End If
    Resume Exit_cmdDelete_Click
    End Sub


    Careful when using DoCmd.SetWarnings(False). It would be better to trap the errors that you are expecting. Also make sure you set it to True after your error would have occured.

    Matt

  3. #3
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    if your in a form you can use
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 3022 Then
    MsgBox "That injury type already exists" & vbCrLf & "Either type a new name or press" & vbCrLf & "ESC to clear the field", vbCritical, "Duplicate Value"
    Response = acDataErrContinue
    End If
    End Sub

    the above traps duplicate entries
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  4. #4
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Originally posted by m.timoney
    if your in a form you can use
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 3022 Then
    MsgBox "That injury type already exists" & vbCrLf & "Either type a new name or press" & vbCrLf & "ESC to clear the field", vbCritical, "Duplicate Value"
    Response = acDataErrContinue
    End If
    End Sub

    the above traps duplicate entries
    I tried this and also the solution mentioned below, but it didn't work.
    It looks like Access doesn't see this as an error.

    Still all tips are welcome.

    Thanks

  5. #5
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    Change to error Err.Number and see what the error is. Then trap for that number.


    Private Sub cmdDelete_Click()
    On Error GoTo Err_cmdDelete_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Exit_cmdDelete_Click:
    Exit Sub

    Err_cmdDelete_Click:
    MsgBox Err.Number

    Resume Exit_cmdDelete_Click
    End Sub

  6. #6
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Originally posted by Rockey
    Change to error Err.Number and see what the error is. Then trap for that number.


    Private Sub cmdDelete_Click()
    On Error GoTo Err_cmdDelete_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Exit_cmdDelete_Click:
    Exit Sub

    Err_cmdDelete_Click:
    MsgBox Err.Number

    Resume Exit_cmdDelete_Click
    End Sub
    I already did this, but (when debugging) Access even doesn't come into the error-section, that's why I suppose Access doesn't see the messages given when performing an SQL-action as an error.

Posting Permissions

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