MS Access Forum / Forms Programming / June 2007
Elapsed Time and Edits
|
|
Thread rating:  |
RobUCSD - 31 May 2007 15:11 GMT 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
Marshall Barton - 31 May 2007 18:33 GMT >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.
 Signature Marsh MVP [MS Access]
RobUCSD - 31 May 2007 19:16 GMT Thanks Marshall,
I'm getting an Error 94 msg, invalid use of null. Any thoughts? Thanks again, rob
> >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 [quoted text clipped - 10 lines] > use, then you will need to lock the ones you don't want > edited. Douglas J. Steele - 31 May 2007 19:19 GMT 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
 Signature Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!)
> Thanks Marshall, > [quoted text clipped - 17 lines] >> use, then you will need to lock the ones you don't want >> edited. RobUCSD - 31 May 2007 19:55 GMT 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
> The problem's likely occurring because there isn't a value for the field for > new records. [quoted text clipped - 28 lines] > >> use, then you will need to lock the ones you don't want > >> edited. Douglas J. Steele - 31 May 2007 20:20 GMT 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)
 Signature Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!)
> 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 [quoted text clipped - 43 lines] >> >> use, then you will need to lock the ones you don't want >> >> edited. RobUCSD - 31 May 2007 20:39 GMT 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
> Why did you change the 60 to 1? That means 1 minute: you say you wanted an > hour (60 minutes). [quoted text clipped - 55 lines] > >> >> use, then you will need to lock the ones you don't want > >> >> edited. Marshall Barton - 31 May 2007 21:50 GMT >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).
 Signature Marsh MVP [MS Access]
RobUCSD - 31 May 2007 23:55 GMT 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
>>So with it set to >>one minute, after that minute elapses it still allows edits. Any ideas, Rob [quoted text clipped - 5 lines] >dor the time limit, the record editing is still in progress >(i.e. editing started when the record became current). Marshall Barton - 01 Jun 2007 01:50 GMT >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] > >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
 Signature Marsh MVP [MS Access]
RobUCSD - 01 Jun 2007 18:31 GMT Marshall, thank you so very much for your persistance and patience. this has really helped me. Hope you have a great weekend.
>>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 - 32 lines] > Resume AllDone >End Sub
|
|
|