stopping fields in certain records being edited

TheTrainMan

Registered User.
Local time
Today, 07:44
Joined
Dec 11, 2002
Messages
18
I want to create a basic log book, OnEnter I want to put the date and time into a field (easy peasy!), I then setfocus to the next field... but how do I stop the date and time from being edited again??

Locked and enabled are for the whole field, I just want to lock each record as I go along

any ideas???
 
Hi

Not sure from your post if the date and time are being set automatically.

If not set the date & time fields as follows:

If IsNull(Me.txtDate) Then Me.txtDate= Date
If IsNull(Me.txtTime) Then Me.txtTime= Time

Code could go in the form's OnCurrent event.

hth

shay :cool:
 
I hope that you are using a single field to hold the date/time. I always set the value in the BeforeUpdate event of the form so that the time is as close to when the record was saved as possible.

Me.LogDate = Now()

You can show this on the form if you want. Just set the locked property to yes so the user can't accidentally change it.

Setting the value in the Current event will dirty the record unnecessarily. You don't want to add code that dirties a record. You want the user to make the first change. That way he won't get confused if he tries to exit a form where he hasn't changed anything and he gets an error message that he can't save the record because some value is missing. because behind the scenes, you have dirtied the form on him.
 
Cheers Shay and Pat, I've used the single field and before update event. But is there a way I can also stop the log entry from being changed? With locked, the field locked is locked in all records... this is good for the date and using before update (but not my rubbish original way of doing it!!!), but this is totally unsuitable for the actual log entry that needs to be entered by hand in each record!!

Thanks in advance!!
 
I don't think I understand the question. I would NOT allow the user to ever modify the log date. It should always be locked and populated automatically via code. The user may need to enter an event date or something like that. You may want to supply a default value. You can do that in the table or in the form. Use Now() if you want both date and time or use Date() if you want just date.
 
Setting the locked property to TRUE means that the FIELD is locked... you cannot edit that field in any record. The date& time thing is no longer an issue - what I want to do is make sure that when a log entry (i.e. the log text) is entered, it cannot be edited. Could I perhaps use after update to 'archive' the log entry so that the only way to view it would be using a read only recordset??? I'm sure I'm on the right track here but not sure which direction to go in!! Any help would be greatly appreciated!! Thanks!
 
Form_Current
If IsDate(Me.YourField) Then
Me.YourField.AllowEdits =False
Else
Me.YourField.AllowEdits =True
End If
End Sub

YourField_AfterUpdate
Form_Current
End Sub
 

Users who are viewing this thread

Back
Top Bottom