문제

I have a continuous form bound to a DAO recordsource. My conditional formatting rule looks like this:

Expression Is: [DateTimeDeleted] IS NOT NULL (fill textbox backgrounds with bright pink)

And then I have a delete button that shows on each record. The code for it is:

Private Sub cmdDelete_Click()
    If Me.NewRecord = False Then
        If IsNull(Me!DateTimeDeleted) = True Then
            Me!DateTimeDeleted = Now()
            DoCmd.RunCommand acCmdSaveRecord
        Else
            Me!DateTimeDeleted = Null
            DoCmd.RunCommand acCmdSaveRecord
        End If
    Else
        Me.Undo
    End If
End Sub

I'm well aware that there's no code here to actually delete the record and I'm OK with that. My complaint is that the conditional formatting appears to be applied only when the form loads. Clicking the button above doesn't make the boxes turn pink for the record being "deleted". Is there some misunderstanding on my part here about how conditional formatting works?

FYI, I'm using MS Access 2013 32bit on Windows 8.1. Maybe that's the source of my problems. It isn't really my choice as the MS Design and Development Action Pack Subscription doesn't allow using Office 2010 anymore.

도움이 되었습니까?

해결책

When dealing with issues like this, I like to use the Refresh command. Your modified code would look like this.

Private Sub cmdDelete_Click()
    If Me.NewRecord = False Then
        If IsNull(Me!DateTimeDeleted) = True Then
            Me!DateTimeDeleted = Now()
            DoCmd.RunCommand acCmdSaveRecord
        Else
            Me!DateTimeDeleted = Null
            DoCmd.RunCommand acCmdSaveRecord
        End If
        Me.Refresh 'This is the inserted code
    Else
        Me.Undo
    End If
End Sub

다른 팁

You can also use Me.Recalc instead of Me.Refresh. Recalc does less overhead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top