locking a form once it has been entered

B

Breezy

I apologize in advance for asking a question that I know has been asnwered
but I so very new to Access that I dont fully understand some of the answers.
This is what I have:

A form set up to be our Purchase Order forms. I have type of startup menu
that the users can choose to open an existing PO or create a new PO. When
they choose a new PO, the form opens to a blank record. I would like to lock
the exsisting records from being edited by the general user in the instance
where they open an existing PO. I would need to be able to edit the closed
date on the PO though so it does not show on an open PO report I have
generated. I have seen several posts to making changes in the current event
property of the field or locking the field. When I select lock, it locks the
field even on the new or blank form.

I need an Access for dummies / simple terminoligy answer so I can understand
and implement correctly.
Thanks!
 
K

Ken Sheridan

First set the Tag property of all the controls you want locked to:

LockMe

i.e. all the bound controls apart from the Closed Date control and any
buttons, unbound navigational controls etc which you want to be enabled for
existing orders as well as new ones. Then in the form's Current event
procedure put the following code:

Dim ctrl as Control
Dim blnLock as Boolean

blnLock = Not Me.NewRecord

For Each ctrl in Me.Controls
If ctrl.Tag = "LockMe" Then
ctrl.Locked = blnLock
ctrl.Enabled = Not blnLock
End If
Next ctrl

If you are unfamiliar with entering code in event procedures this is how its
done:

Select the form object in form design view by clicking on the small grey
square in its top left corner, and open its properties sheet if its not
already open. Then select the On Current event property in the properties
sheet. Click on the 'build' button; that's the one on the right with 3 dots.
Select 'Code Builder' in the dialogue, and click OK. The VBA window will
open at the event procedure with the first and last lines already in place.
Enter the lines of code between these two existing lines.

Ken Sheridan
Stafford, England
 
B

Breezy

That helped!! Thanks!!

Ken Sheridan said:
First set the Tag property of all the controls you want locked to:

LockMe

i.e. all the bound controls apart from the Closed Date control and any
buttons, unbound navigational controls etc which you want to be enabled for
existing orders as well as new ones. Then in the form's Current event
procedure put the following code:

Dim ctrl as Control
Dim blnLock as Boolean

blnLock = Not Me.NewRecord

For Each ctrl in Me.Controls
If ctrl.Tag = "LockMe" Then
ctrl.Locked = blnLock
ctrl.Enabled = Not blnLock
End If
Next ctrl

If you are unfamiliar with entering code in event procedures this is how its
done:

Select the form object in form design view by clicking on the small grey
square in its top left corner, and open its properties sheet if its not
already open. Then select the On Current event property in the properties
sheet. Click on the 'build' button; that's the one on the right with 3 dots.
Select 'Code Builder' in the dialogue, and click OK. The VBA window will
open at the event procedure with the first and last lines already in place.
Enter the lines of code between these two existing lines.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top