Link to home
Start Free TrialLog in
Avatar of gdunn59
gdunn59

asked on

How Can I Disable a Delete Button if The Form is Blank

I have code to delete the current record on a form.  I want to be able to disable this button if the form is blank.

I have included the code for the record deletion.

How can I do this?

Thanks,
gdunn59
Private Sub cmdDelRec_Click()
On Error GoTo Err_cmdDelRec_Click
Dim rtn As String

DoCmd.SetWarnings False
    rtn = MsgBox("Are you sure you want to Cancel this record?", vbYesNo)
    If rtn = vbYes Then
        RunCommand acCmdDeleteRecord
        'DoCmd.GoToRecord , , acPrevious
        DoCmd.GoToRecord , , acNewRec
        Me.InquiryNum.SetFocus
        Me.Requery
    Else
        Cancel = True
        Me.InquiryNum.SetFocus
    End If

DoCmd.SetWarnings True

Exit_cmdDelRec_Click:
    Exit Sub

Err_cmdDelRec_Click:
    Cancel = True
    Resume Exit_cmdDelRec_Click
    
End Sub

Open in new window

SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gdunn59
gdunn59

ASKER

Ok.  Thanks!
Avatar of gdunn59

ASKER

Worked like a charm once I changed the Else Statement to True instead of False.  Thanks again