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?