Dirty Property

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Dirty Property

Post by D Willett »

On a date field before update I'm trying to prevent the user from editing a date once it has been set.
If the field is empty then the user can add a date, if the field already has a date then the user cannot.
Should I lock the field on open or use the dirty event which doesn't work as the code below because when a new date is entered the dirty event fires anyway?:

Code: Select all

Private Sub BookOutDate_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
If Me.BookOutDate > 0 Then
MsgBox "You Have Already Set The Book Out Date" & vbCrLf & _
"You Will Need To Change The Dates Through The Delay Portal", , "Dates"
Cancel = True
DoCmd.Close acForm, Me.Name
Exit Sub
End If
End If

End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Dirty Property

Post by HansV »

If you lock the text box the moment it has been filled, you don't leave any room for corrections. I'd use the On Current event of the form to lock the text box if it is filled:

Code: Select all

Private Sub Form_Current()
    Me.BookOutDate.Locked = Not IsNull(Me.BookOutDate)
End Sub
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Dirty Property

Post by D Willett »

Great stuff Hans. The dirty event was getting itself in a little pickle...

Thanks
Cheers ...

Dave.