Editing of time and date field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a subform that shows in datasheet view with fields Start Time and Stop
Time. These are set up to double click in field and date and time will be
entered to each. I need to set these fields so that once the time and date
has been entered, it cannot be changed, at least in front screen form view.
I tried searching previous posts and tried the following code:

on the current event of the form:
Me.ControlName.Locked = Not Me.NewRecord

And

On the After Update event of the form:
Me.ControlName.Locked = True

I can still click in the fields and it updates to the current time. Also,
with this being "new record", will the user be able to click to start time,
get out of the db, come back at a later time, go to same record and enter
stop time? We are using this as a time management tool.
Thanks in advance for any help with this problem!
Phisaw
 
Once the record's been added to the table, it's no longer a new record, so
it'll be locked the next time they go into the database.

Perhaps what you want is Me.ControlName.Locked = Len(Me.ControlName & "") >
0
 
Thank you Douglas for the reply, but I tried the code you gave in both the
Current and After Update events for the form and it still allows changes to
the times already entered. Should the code go in some place else?
 
Is the name of the text box the same as the name of the field to which it's
bound? That sometimes causes problems.

If, say, both the text box and the data field are named StartTime, try
renaming the text box to txtStartTime, and using Me.txtStartTime.Locked =
Len(Me.txtStartTime & "") > 0
 
Doug, I changed the name and entered the code you gave and I can still change
the date & time by double clicking in field. Here is code related to text
box:
Text Box Name: txtTimeStart
Control Source: TimeStart
After Update: Me.txtStartTime.Locked = Len(Me.txtStartTime & "") > 0
Double Click: txtStartTime = Now()

Thanks again for all your help!
Phisaw
 
Doug,

I have the following code in the DoubleClick event for the field I want to
lock:

If IsNull (me.txtStartTime) Then
Me.txtStartTime = Now()
Else
Me.txtStartTime.Locked = True

This is in datasheet view and works okay, but if the cursor is say in the
tech field and I click in the StartTime column it changes the time in that
row. Any way to prevent this? Maybe this code isn't the best for this?

Your help with this is much appreciated!
Phisaw
 
Sorry, I'm not sure I understand what you're describing.

Are you saying that you've got multiple rows of data on your form, and the
wrong row is getting updated?
 
Let me try to explain this better - it may be just the way Access works -
I'm not sure, but wanted to check with experts. The subform is in datasheet
view. If I have 5 records (rows) and the start time is locked per code in
previous msg, and the cursor is on row 2 say and I click in row 6 (new
record) start time, it will change the date and time for row 2. Is this
correct?
Thanks for your help with this!
Phisaw
 
You have to ensure that you've selected the correct row before you
double-click.
 
Back
Top