Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    delete button (2003)

    If have put a delete button on my form.
    I have put this code on it:
    Private Sub cmdWissen_Click()
    Dim Answer1, Answer2, Answer3 As Integer

    Answer1 = MsgBox("Ben je zeker dat je deze opmerking wilt verwijderen? ", vbYesNo + vbExclamation, "Verwijderen opmerking")

    On Error GoTo Err_cmdWissen_Click

    If Answer1 = vbYes Then
    DoCmd.RunCommand acCmdDeleteRecord
    MsgBox "opmerking is verwijderd, hopelijk is dit geen vergissing.", vbOKOnly + vbExclamation, "Verwijderd"
    ElseIf Answer1 = vbNo Then
    MsgBox "Je hebt het verwijderen geannuleerd", vbOKOnly + vbExclamation, "Annulatie"
    End If

    Exit_cmdWissen_Click:
    Exit Sub

    Err_cmdWissen_Click:
    MsgBox "Deze opmerking is reeds in gebruik, je kan dit niet verwijderen", vbInformation
    Resume Exit_cmdWissen_Click

    End Sub

    When the record is in use, there is no problem.
    But when the record is not in use (link to tblfactuur) I'll get an second yesno msgbox.
    How can I capture this?
    I've put my mdb in attachement, stripped of course.
    Attached Files Attached Files

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

    Re: delete button (2003)

    You can use DoCmd.SetWarnings False to suppress the built-in warning. It is a good idea to turn the warnings on again at the end of the code.

    Private Sub cmdWissen_Click()
    Dim Answer1 As Integer
    If NewRecord Then
    Exit Sub
    End If
    Answer1 = MsgBox("Ben je zeker dat je deze opmerking wilt verwijderen? ", _
    vbYesNo + vbExclamation, "Verwijderen opmerking")
    On Error GoTo Err_cmdWissen_Click
    If Answer1 = vbYes Then
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    MsgBox "opmerking is verwijderd, hopelijk is dit geen vergissing.", _
    vbOKOnly + vbExclamation, "Verwijderd"
    Else
    MsgBox "Je hebt het verwijderen geannuleerd", _
    vbOKOnly + vbExclamation, "Annulatie"
    End If

    Exit_cmdWissen_Click:
    DoCmd.SetWarnings True
    Exit Sub

    Err_cmdWissen_Click:
    MsgBox "Deze opmerking is reeds in gebruik, je kan dit niet verwijderen", _
    vbInformation
    Resume Exit_cmdWissen_Click
    End Sub

    I added code at the beginning to exit if the current record is a new one (it also caused the "Deze opmerking is reeds in gebruik" message.

  3. #3
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: delete button (2003)

    Yes, that works fine.
    But would it not be better if I just disable the button when it is use?
    With dlookup function?
    Dim GeZocht
    GeZocht = DLookup("selopmerkingen", "tblfactuur", "idopmerkingen = selopmerkingen")
    If (GeZocht) = "" Then
    Me.cmdWissen.Visible = True
    Else
    Me.cmdWissen.Visible = False
    End If
    But when I put this code on form_load or form_current, it do it for all the records.
    It is a Continuous Form, mayb that is my problem?

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

    Re: delete button (2003)

    > It is a Continuous Form, maybe that is my problem?

    Yes indeed. A continuous form contains only one set of controls. If you disable a control, it is disabled in all records. So your idea won't work in a continuous form.

Posting Permissions

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