Locking Record when a field has a value

  • Thread starter Thread starter Elli S
  • Start date Start date
E

Elli S

Hi, I have a work order form that must have the ability
to be edited, until the job is invoiced. At that point,
the work order should be locked.

I know I can created a locked version of the worksheet
based on the field, but was wondering if I can add a code
to the open event that would do lock records automatically.

Any assistance you can offer would be greatly appreciated.
 
Hi Elli,

Using the Current Event of the form you can modify the AllowEdits property
of the form - depending on your form this might be what you need however it
locks all controls, including unbound
ones that you might have for record navigation.

An alternative is to create a procedure which loops through the controls and
toggles the locked property of the control. I typically use tag property of
each control to flag the controls that I want to togglelock. In other words
I select all the lockable controls, then click the Other Tab of the property
sheet and in the Tag property I type "ToggleLock" (without the quotes). Then
in the current event of the form I call a ToggleLock procedure which either
locks or unlocks the appropriate fields depending on the fLock parameter.

By putting this code in the current event of the form, it gets executed
after all record navigation including when the form opens and goes to the
first record. If the same form is used for entering the invoice number then
you also need to call it from the AfterUpdate event of the form.

if isnull(me.InvoiceNum)
'unlock
togglelocks false
else
'lock
togglelocks true
endif

private sub togglelocks(flock as boolean)
dim ctl as control
for each ctl in me.controls
if ctl.tag = "ToggleLock" then
ctl.locked = flock
endif
next ctl
end sub
 
Elli

Another approach might be to change the CanEdit property of the form, based
on the value of that field.

Good luck

Jeff Boyce
<Access MVP>
 
Jeff said:
Elli

Another approach might be to change the CanEdit property of the form,
based on the value of that field.


Hi Jeff,

Is that the same as the AllowEdits property? ;-)

<gd&r>
 
Back
Top