Locking or Disabling Specific Records/ Set Focus

  • Thread starter Thread starter dcardoza
  • Start date Start date
D

dcardoza

I am a aware of the RecordsLock property as it pertains to
shared databases, but this is not what I think I need or
want here.

I have a form with a date as well as several other fields
on a form. If the current day exceeds the entered day by
more than 7 I want to disable the current record,
preventing anyone from editing it at all.

Here is what I have....

Private Sub Form_Current()

' If Now() - ClassDate > 7 Then
' ClassID.Enabled = False
' ClassNameLookup.Enabled = False
Etc
' Else
' ClassID.Enabled = True
' ClassNameLookup.Enabled = True
Etc

' End If


The problem that occured today is that I tried to open
this form, and it said it couldn't move the focus to
ClassID, which is the first field. After thinking, it
eventually made sense..... if the LAST class I entered was
more than 7 days ago (which it was), the form can't open
because it can't set the focus to a field that has been
disabled.

Then I thought to automatically open to a "new" record
once the form is open (using the open event). That still
did not work. I also tried using ClassID.Enabled = True
when the form is opened, but that also did not work.

Can anyone help. I think I am in the right direction
here.... I can't set the focus to something that is
disabled. If I "comment out" the code from above (the on
current event) I seem to work ok.

Thanks in Advance,
Don
 
Try turning it around, and doing a check for new record

If me.NewRecord or (Now() - ClassDate <= 7) then
EnableForm
else
DisableFOrm
endif

Another option would be to always disable the form for edits
Me.AllowEdits = false
Me.AllowDelteions = false
me.AllowAdditions = True

then put in a button to turn editing on
Sub cmdEdit_Click
if RecordTooOld() then
MsgBox"You cannot edit. Record too old"
else
me.allowedits = true
endif
This second method has the advantage that records won't be
accidentally altered
 
Back
Top