Elapsed Time and Edits

  • Thread starter Thread starter RobUCSD via AccessMonster.com
  • Start date Start date
R

RobUCSD via AccessMonster.com

I need to be able to set a record to allowEdits=False if the creation of the
record is over 1hr old. I'm not sure how to do this. It needs to be just the
record that can't be edited, not the entire form.

Your help is greatly appreciated. Thanks, Rob
 
RobUCSD said:
I need to be able to set a record to allowEdits=False if the creation of the
record is over 1hr old. I'm not sure how to do this. It needs to be just the
record that can't be edited, not the entire form.


Depends on what else you are doing in the form.

The simplest thing is to use a line of code in the form's
Current event:

Me.AllowEdits = (DateDiff("n", datefield, Now) > 60)

If you have unbound controls on the form that you need to
use, then you will need to lock the ones you don't want
edited.
 
Thanks Marshall,

I'm getting an Error 94 msg, invalid use of null. Any thoughts? Thanks
again, rob
 
The problem's likely occurring because there isn't a value for the field for
new records.

Try changing to:

If Me.NewRecord = False Then
Me.AllowEdits = (DateDiff("n", datefield, Now) > 60)
Else
Me.AllowEdits = True
End If
 
Hi Doug, I don't get the msg any more, but it doesn't seem to be working
properly. It doesn't allow records less than one our since it's creation
(fldTimeStamp) to be edited. here's the code,

If Me.NewRecord = False Then
Me.AllowEdits = (DateDiff("n", Me.fldTimeStamp, Now) > 1)
Else
Me.AllowEdits = True
End If

I appreciate your help
 
Why did you change the 60 to 1? That means 1 minute: you say you wanted an
hour (60 minutes).

However, it looks like the comparison operator is incorrect: Since you want
to allow edits for those records less than an hour old, so you want

Me.AllowEdits = (DateDiff("n", Me.fldTimeStamp, Now) < 60)

or

Me.AllowEdits = (DateDiff("h", Me.fldTimeStamp, Now) < 1)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


RobUCSD said:
Hi Doug, I don't get the msg any more, but it doesn't seem to be working
properly. It doesn't allow records less than one our since it's creation
(fldTimeStamp) to be edited. here's the code,

If Me.NewRecord = False Then
Me.AllowEdits = (DateDiff("n", Me.fldTimeStamp, Now) > 1)
Else
Me.AllowEdits = True
End If

I appreciate your help
 
Sorry Doug, I changed it to 1 minute for testing purposes. So with it set to
one minute, after that minute elapses it still allows edits. Any ideas, Rob
 
RobUCSD said:
So with it set to
one minute, after that minute elapses it still allows edits. Any ideas, Rob


Post the code that you have in the form's Current event.

Don't forget that you have to move to the record after the
timelimit has elapsed. If you just select a record and wait
dor the time limit, the record editing is still in progress
(i.e. editing started when the record became current).
 
Here's the code. I'm trying to test for 2 separte items in order to allow
edits, elaplsed time <5min and that the person who created the record is the
one is trying to edit it. I know it's kind of a mess, but I sure would
appreciate your help. Thanks, rob

Private Sub Form_Current()

On Error GoTo Form_Current_Error

If CurrentUser <> Me.txtCreator Then
Me.AllowEdits = False
MsgBox "You are not the author or too much time has passed to edit this
record."

Else
If Me.NewRecord Then Me.AllowEdits = True
End If

Else

If Me.AllowEdits = (DateDiff("n", Me.fldTimeStamp, Now) < 5) Then
Me.AllowEdits = False
MsgBox "You are not the author or too much time has passed to edit this
record"

Else

Me.AllowEdits = True

On Error GoTo 0
Exit Sub

Form_Current_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Form_Current of VBA Document Form_fsubRNnotes"

End Sub
 
RobUCSD said:
Here's the code. I'm trying to test for 2 separte items in order to allow
edits, elaplsed time <5min and that the person who created the record is the
one is trying to edit it. I know it's kind of a mess, but I sure would
appreciate your help. Thanks, rob

Private Sub Form_Current()

On Error GoTo Form_Current_Error

If CurrentUser <> Me.txtCreator Then
Me.AllowEdits = False
MsgBox "You are not the author or too much time has passed to edit this
record."

Else
If Me.NewRecord Then Me.AllowEdits = True
End If

Else

If Me.AllowEdits = (DateDiff("n", Me.fldTimeStamp, Now) < 5) Then
Me.AllowEdits = False
MsgBox "You are not the author or too much time has passed to edit this
record"

Else

Me.AllowEdits = True

On Error GoTo 0
Exit Sub

Form_Current_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Form_Current of VBA Document Form_fsubRNnotes"

End Sub


What? That code won't even compile so it doesn't matter
what the test does not do. You can help yourself avoid
extraneous Else statements if you indent the code between
block type statement such as If - Else - End If, With - End
With, For - Next, Do - Loop, etc.

Here's my attemp to clean it up. Be sure to Compile it (and
fix any compile errors) before attempting to test it.

Private Sub Form_Current()
On Error GoTo Form_Current_Error

If Me.NewRecord _
OR (CurrentUser = Me.txtCreator _
AND DateDiff("n", Me.fldTimeStamp, Now) <= 5) Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
MsgBox "You are not the author . . ."
End If

AllDone:
Exit Sub

Form_Current_Error:
On Error Resume Next
MsgBox "Error " & Err.Number & " -" & Err.Description _
& vbCrLf & " in Form_Current of Form_fsubRNnotes"
Resume AllDone
End Sub
 
Marshall, thank you so very much for your persistance and patience. this has
really helped me. Hope you have a great weekend.

Marshall said:
Here's the code. I'm trying to test for 2 separte items in order to allow
edits, elaplsed time <5min and that the person who created the record is the
[quoted text clipped - 34 lines]

What? That code won't even compile so it doesn't matter
what the test does not do. You can help yourself avoid
extraneous Else statements if you indent the code between
block type statement such as If - Else - End If, With - End
With, For - Next, Do - Loop, etc.

Here's my attemp to clean it up. Be sure to Compile it (and
fix any compile errors) before attempting to test it.

Private Sub Form_Current()
On Error GoTo Form_Current_Error

If Me.NewRecord _
OR (CurrentUser = Me.txtCreator _
AND DateDiff("n", Me.fldTimeStamp, Now) <= 5) Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
MsgBox "You are not the author . . ."
End If

AllDone:
Exit Sub

Form_Current_Error:
On Error Resume Next
MsgBox "Error " & Err.Number & " -" & Err.Description _
& vbCrLf & " in Form_Current of Form_fsubRNnotes"
Resume AllDone
End Sub
 
Back
Top