No Updating allowed

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?
 
B

Brian Bastl

Using the form's On Current event, lock the date control if it is an
existing record:

Me.MyDate.Locked = Not Me.NewRecord

Brian
 
A

Allen Browne

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.)
 
G

Guest

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.)

--
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?
 
G

Guest

But this would not help new records being entered.
We need to be able to add new records and not be able to go back later and
change the date....

Help
 
A

Allen Browne

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.)

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?
 
B

Brian Bastl

Dan,

Your date control would be editable if you are entering a new record, but
locked if it is an existing record.

Brian
 
G

Guest

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

--
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?
 
A

Allen Browne

You used the BeforeUpate event of the control, instead of the AfterUpdate
event of the form.

And to repeat what I told you in the first reply:
(You will need to add error handling to SetFocus to something else
if the date field has focus when Access tries to disable it.)

If error handling is a new concept, see:
http://allenbrowne.com/ser-23a.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

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?
 

Ask a Question

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.

Ask a Question

Top