G
Guest
How can I make a date field on a form non-changable. Once a date has been
entered once it cannot be changed?
entered once it cannot be changed?
Allen Browne said:Add this code to the Current event procedure of the form, replacing Date1
with the name of your date field:
Dim bEnabled As Boolean
With Me.[Date1]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Once the date has been entered and you move away from that record, it is
locked from then on.
(You will need to add error handling to SetFocus to something else if the
date field has focus when Access tries to disable it.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Dan @BCBS said:How can I make a date field on a form non-changable. Once a date has been
entered once it cannot be changed?
Dan @BCBS said:I added this but it has no effect, I can still change the dates:
Please help...
Dim bEnabled As Boolean
With Me.[TR_DATE_TIMERCVD_HOI]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Allen Browne said:Add this code to the Current event procedure of the form, replacing Date1
with the name of your date field:
Dim bEnabled As Boolean
With Me.[Date1]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Once the date has been entered and you move away from that record, it is
locked from then on.
(You will need to add error handling to SetFocus to something else if the
date field has focus when Access tries to disable it.)
Dan @BCBS said:How can I make a date field on a form non-changable. Once a date has
been
entered once it cannot be changed?
Allen Browne said:If you want the change to lock the field as soon as the record is saved
(without having to move record and back), add the code to the form's
AfterUpdate event as well.
BTW, there's a dot missing, i.e.:
.Enabled = bEnabled
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Dan @BCBS said:I added this but it has no effect, I can still change the dates:
Please help...
Dim bEnabled As Boolean
With Me.[TR_DATE_TIMERCVD_HOI]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Allen Browne said:Add this code to the Current event procedure of the form, replacing Date1
with the name of your date field:
Dim bEnabled As Boolean
With Me.[Date1]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Once the date has been entered and you move away from that record, it is
locked from then on.
(You will need to add error handling to SetFocus to something else if the
date field has focus when Access tries to disable it.)
How can I make a date field on a form non-changable. Once a date has
been
entered once it cannot be changed?
Dan @BCBS said:Ok, I added this to the event for the date field. I get "ERROR you can't
disable a control while it has the focus"
What am I doing wrong???
Private Sub TR_DATE_TIMERCVD_HOI_BeforeUpdate(Cancel As Integer)
Dim bEnabled As Boolean
With Me.[TR_DATE_TIMERCVD_HOI]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With
End Sub
Allen Browne said:If you want the change to lock the field as soon as the record is saved
(without having to move record and back), add the code to the form's
AfterUpdate event as well.
BTW, there's a dot missing, i.e.:
.Enabled = bEnabled
Dan @BCBS said:I added this but it has no effect, I can still change the dates:
Please help...
Dim bEnabled As Boolean
With Me.[TR_DATE_TIMERCVD_HOI]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
:
Add this code to the Current event procedure of the form, replacing
Date1
with the name of your date field:
Dim bEnabled As Boolean
With Me.[Date1]
bEnabled = ((Me.NewRecord) Or (IsNull(.Value)))
If .Enabled <> bEnabled Then
Enabled = bEnabled
End If
End With
Once the date has been entered and you move away from that record, it
is
locked from then on.
(You will need to add error handling to SetFocus to something else if
the
date field has focus when Access tries to disable it.)
How can I make a date field on a form non-changable. Once a date has
been
entered once it cannot be changed?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.