jjjjjjjjjjj
jjjjjjjjjjj

Reputation: 447

Hide button for new row in Access 2013 continuous form

I have a continuous form in Access with Allow Additions set to Yes. I'm trying to enable or disable a deletion button depending on if the user has filled in data in that record. In other words, I want to hide the button for only the blank record at the bottom of the form.

I tried the following in the Form_Current event but it enables or disables all buttons at the same time, and it only runs when I click on a record. I need it to run immediately and update when I add a new row.

If Me.NewRecord Then
    btnDelete.Visible = False
Else
    btnDelete.Visible = True
End If

EDIT: with working code.

If Me.NewRecord Then
    'show error message
    MsgBox ("Unable to delete empty row.")
Else
    'deletion code
End If

Upvotes: 0

Views: 1164

Answers (2)

Jim B
Jim B

Reputation: 459

Here is the above code with handling when the user starts entering data in the "add" row and then clicks delete on that row.

If Me.NewRecord Then
    'code to undo/clear partially entered new record
    If Me.Dirty Then
        DoCmd.RunCommand acCmdUndo
    End If
    
Else
    If MsgBox("Are you sure you want to delete this xxxx record?", vbYesNo) = vbYes Then
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.RunCommand acCmdDeleteRecord
    End If
End If

Upvotes: 0

dbmitch
dbmitch

Reputation: 5386

Continuous forms won't allow that - everything looks the same.

You might be able to add code to the btnDelete_Click event that checks for Me.NewRecord and just exits the sub

Upvotes: 1

Related Questions