Lock recordset

Webster01

Registered User.
Local time
Today, 13:01
Joined
Mar 25, 2002
Messages
15
I would like to lock from edits any recordset that is greater than 24 hours old. Is there a way through code that this could be accomplished?

(for example, as I enter new data into a form, I wouldlike to be able to go back and change that data at any time during the first day that I have added the record, but once that day has passed, I would like for this record to be locked to edits)

Thanks,

Doug
 
Doug,

One thought.

Create a field in your table called, say, Created.

In your form, create a hidden textbox -- called, say, txtCreated -- that is bound to your Created field.

In the On Current event of the form, put code that checks whether or not the current record is a new record (search Help for "New Record" -- there's a pretty good example there on how to use code to figure out if the current rec is new).

If the rec is new, run code that puts the current date and time into the txtCreated field.

If it isn't a new record, subtract Now() from txtCreated; if the result is greater than 1, then me.allowedits = False.

You can put code like the following into the Current Event (I'm improvising -- not workable, tested code but hopefully something to help you move on):

Me.allowedits = False

If me.newrecord then
me.allowedits = True
me.txtcreated.value = now()
exit sub
End if

'otherwise...

Dim vage as variant
vage = now() - me.txtcreated.value

If vage > 1 then 'rec's over a day old
'leave sub -- no edits allowed by default
exit sub

Else

'rec's less than a day old
me.allowedits = True

end if

End sub

Regards,
Tim
 
Last edited:

Users who are viewing this thread

Back
Top Bottom