Locking records after 3 weeks (or x amount of time)

S

Susy

I have a database on a network with several users. They each have a front end
with all their forms and reports for entering and printing time and expenses.
The database on the network contains only the tables.

I'd like the records to be locked (i.e., not able to be altered or deleted)
after three weeks - one pay period plus one week for review and correction.
Is this possible?
 
T

Tom Wickerath

Hi Susy,

Yes, this can be done. The easiest method might be to set the form
properties in VBA code using the Form_Current() event procedure. Are you
familiar with using VBA code?

You would need to create a new field in the table for the underlying
recordset to record the date that the record was created, if you do are not
already saving this date, although I suspect that you already have this date
available as a field on the form. Open your form in design view. Then open
the VBE (Visual Basic Editor), by clicking on View > Code. Select Form from
the dropdown list on the left side. Select Current from the dropdown list on
the right side. (You can delete the default Form Load procedure if it is
empty and doesn't go away by itself).

Make sure to have the DateEntered field available to the form (ie. add it to
the query if you need to). You can set the visible property for this bound
text box to no if you don't want it displayed. Then copy the following code
into the Form_Current event procedure:

Private Sub Form_Current()
On Error GoTo ProcError

If Date - Me.DateEntered > 21 Then

Me.AllowEdits = False
Me.AllowDeletions = False

Else
Me.AllowEdits = True
Me.AllowDeletions = True

End If

If Me.NewRecord Then
Me.DateEntered = Date
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc

End Sub


If the DateEntered value is null, the IF...THEN condition will evaluate to
False, so the record will be editable. You can add additional code to make
sure that all new records have a DateEntered value:

If Me.

Tom
______________________________________

:

I have a database on a network with several users. They each have a front end
with all their forms and reports for entering and printing time and expenses.
The database on the network contains only the tables.

I'd like the records to be locked (i.e., not able to be altered or deleted)
after three weeks - one pay period plus one week for review and correction.
Is this possible?
 
T

Tom Wickerath

Hi Susy,
That said, I entered your code and am still able to edit the records that I
want to lock. Here's what I typed. My field is date_entered. I do have a
field called "Date" - that's the actual day of the work. Should I change that?

Yes. Date is a reserved word, and should not be used as the name of any
field, object or control that you name in Access:

Reserved Words
Reserved Words in Microsoft Access
http://support.microsoft.com/?id=286335

List of reserved words in Jet 4.0
http://support.microsoft.com/?id=321266
If Date - Me.Date_Entered > 1 Then

I thought you wanted three weeks. The above condtion would lock the form for
edits after 1 day. I tested the code I provided before sending it, and it
worked fine on my PC.

Tom
_______________________________________

:

Hello Tom,

Yes, I work a lot with VBA code. I'm not an expert by any means but I manage
to fly by the seat of my pants quite well.

And you're right - I always have a "date entered" field, usually defaulted
to today's date.

That said, I entered your code and am still able to edit the records that I
want to lock. Here's what I typed. My field is date_entered. I do have a
field called "Date" - that's the actual day of the work. Should I change that?

Private Sub Form_Current()
On Error GoTo ProcError

If Date - Me.Date_Entered > 1 Then
Me.AllowEdits = False
Me.AllowDeletions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
End If

If Me.NewRecord Then
Me.Date_Entered = Date
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ":" & Err.Description, vbCritical, "Error
in procedure Form_Current..."
Resume ExitProc

End Sub

__________________________________________

:

Hi Susy,

Yes, this can be done. The easiest method might be to set the form
properties in VBA code using the Form_Current() event procedure. Are you
familiar with using VBA code?

You would need to create a new field in the table for the underlying
recordset to record the date that the record was created, if you do are not
already saving this date, although I suspect that you already have this date
available as a field on the form. Open your form in design view. Then open
the VBE (Visual Basic Editor), by clicking on View > Code. Select Form from
the dropdown list on the left side. Select Current from the dropdown list on
the right side. (You can delete the default Form Load procedure if it is
empty and doesn't go away by itself).

Make sure to have the DateEntered field available to the form (ie. add it to
the query if you need to). You can set the visible property for this bound
text box to no if you don't want it displayed. Then copy the following code
into the Form_Current event procedure:

Private Sub Form_Current()
On Error GoTo ProcError

If Date - Me.DateEntered > 21 Then

Me.AllowEdits = False
Me.AllowDeletions = False

Else
Me.AllowEdits = True
Me.AllowDeletions = True

End If

If Me.NewRecord Then
Me.DateEntered = Date
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc

End Sub


If the DateEntered value is null, the IF...THEN condition will evaluate to
False, so the record will be editable. You can add additional code to make
sure that all new records have a DateEntered value:

If Me.

Tom
______________________________________

:

I have a database on a network with several users. They each have a front end
with all their forms and reports for entering and printing time and expenses.
The database on the network contains only the tables.

I'd like the records to be locked (i.e., not able to be altered or deleted)
after three weeks - one pay period plus one week for review and correction.
Is this possible?
 
S

Susy

Hello Tom,

Yes, I work a lot with VBA code. I'm not an expert by any means but I manage
to fly by the seat of my pants quite well.

And you're right - I always have a "date entered" field, usually defaulted
to today's date.

That said, I entered your code and am still able to edit the records that I
want to lock. Here's what I typed. My field is date_entered. I do have a
field called "Date" - that's the actual day of the work. Should I change that?

Private Sub Form_Current()
On Error GoTo ProcError

If Date - Me.Date_Entered > 1 Then
Me.AllowEdits = False
Me.AllowDeletions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
End If

If Me.NewRecord Then
Me.Date_Entered = Date
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ":" & Err.Description, vbCritical, "Error
in procedure Form_Current..."
Resume ExitProc

End Sub
 
S

Susy

I should add that I changed the number of days from "21" to "1" to see if it
would affect the results. It didn't.
 
T

Tom Wickerath

Hi Susy,

Glad I could help. Please consider marking my response as "answered". I'm
trying to work my way towards the coveted bronze icon, but it sure is a *s l
o w* process.

From the Communities Help:
Rate a post as an answer (or not an answer) to your question
(Note that you cannot rate a post that you have authored.)

When someone replies to a question you asked, you can rate this post as an
answer, or not an answer to your question. By rating a post as an answer, you
help others find the answer more quickly, you give credit to the person who
posted the answer, and you help increase the quality of answers in the
discussion group.

In the thread pane, select the post that is a response to a question you
asked.
In the message pane, do one of the following:
If the post answers your question, click Yes next to Did this post answer
the question?
If the message was not helpful to you, click No next to Did this post answer
the question?
The post you rated is now marked as an answer, and the thread is now marked
as an answered question, and will be returned in search results.
Additionally, the person who posted this answer is credited with an answered
question (this is added to their profile information).

Thanks,
Tom
________________________________
 
Top