Lock all Controls

G

Grace

Hi,

I need to Lock all controls of a FORM1 and a SUBFORM (within the form1) through a command
button

How can I do?

Thanks in advance.

Grace.-
 
P

pddxxx

Something like this should work from a command button event procedure:

dim ctl as control
on error resume next
for each ctl in me.controls
ctl.locked = true
next ctl
set ctl = nothing
on error goto 0

Hope this helps,

Peter De Baets
http://www.peterssoftware.com
 
U

UTOPIAN

Hello! thanks for reply

Sorry!I spoke badly!

I need the command button ENABLE controls when it is pressed... and that
LOCK when it returns to pressure AND the switch to next RECORD.

Thanks!
 
A

Allen Browne

See:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Hi,

I need to Lock all controls of a FORM1 and a SUBFORM (within the form1)
through a command
button

How can I do?

Thanks in advance.

Grace.-
 
P

Priscilla

I implemented the code you had listed on your site. (Works like a
charm-thanks. However in my case I would like to only lock down certain
records that have an attribute. For example, I have 700 records that contain
various fields. One of these fields is of type yes/no. I would only like to
lock the form for records that have the "yes" selected, versus locking all
forms. Can the method you displayed here be used to accomplish this?
 
A

Allen Browne

Use the Current event of the form to call:
Call LockBoundControls(Me, Nz(Me.[YourYesNoField],False))

You probably want to do this in Form_AfterUpdate as well.
 
P

Priscilla

Thank you so much. That is exactly what I was looking for. Much appreciated
--
Priscilla


Allen Browne said:
Use the Current event of the form to call:
Call LockBoundControls(Me, Nz(Me.[YourYesNoField],False))

You probably want to do this in Form_AfterUpdate as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Priscilla said:
I implemented the code you had listed on your site. (Works like a
charm-thanks. However in my case I would like to only lock down certain
records that have an attribute. For example, I have 700 records that
contain
various fields. One of these fields is of type yes/no. I would only like
to
lock the form for records that have the "yes" selected, versus locking all
forms. Can the method you displayed here be used to accomplish this?
 
T

Tim

I have successfully implemented the referenced code with one exception;
When I set my form "On Load" property to =LockBoundControls([Form],True) I
get the following error - "Compile error" "Expected: line number or label or
statement or end of statement" The equal sign is highlighted. Does something
need to go before this? I'm assuming "Form" in the code needs to be replaced
by the name of my form?

Thanks!

Tim
 
S

sldfkj

"Grace" <[email protected]> 写入邮件 Hi,

I need to Lock all controls of a FORM1 and a SUBFORM (within the form1) through a command
button

How can I do?

Thanks in advance.

Grace.-
 
E

Evi

I guess that you only want this to happen with text boxes.
I also guess that you may have got an answer to this in another newsgroup. I
don't think you should have posted to quite so many newsgroups in one go :)


For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Enabled = True
End If
Next ctl

Evi


"Grace" <[email protected]> ????
Hi,

I need to Lock all controls of a FORM1 and a SUBFORM (within the form1)
through a command
button

How can I do?

Thanks in advance.

Grace.-
 
E

Evi

Errr..actually I meant...

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Enabled = false
End If
Next ctl


The code for the subform is the same except the first line is

For Each ctl In Me.TheNameOfYourSubform.Form.Controls




You'll need to substitute the real name of your subform
 

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