Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unlock part of Form 1

Status
Not open for further replies.

LakotaMan

Instructor
Aug 21, 2001
240
US
Hi again to all,

I am trying to set up a form that I can reuse in different situations, allowing and not allowing data entry depending on the switchboard button chosen.

I have a button on the Switchboard to open the form in data entry mode. I have another to open it in Read Only. Problem is, I'd like to enable one control for entry, while locking out the rest. It seemed opening in Read Only was a quick way to lock up all controls, until now, when I want to open one up.

Is my only choice to specify on the click event which controls to lock and unlock one at a time? This form has textboxes, and comboboxes, so am not sure how a loop would be able to handle this.

Thanks in advance,
Tru
 
Looping thru the controls might do the trick. You don't say much of what your criteria should be, but here's something to play with (set the tag property of the control you don't want to toggle to something, here I just test for any value (length > 0), and toggle the locked property):

[tt]dim ctl as control
for each ctl in me.controls
if len(ctl.tag & vbNullstring)>0 then
if ctl.controltype = actextbox or
ctl.controltype = accombobox then
ctl.locked = not ctl.locked
end if
end if
next ctl[/tt]

You can use the .name property and/or the .tag property of the control in your testing (btw - this suggestion is typed not tested, so there might be typos...)

- a step in the direction you need?

Roy-Vidar
 
Roy,

Did as you suggested and it worked like a charm! Here's the code I wrote (this is just part of the procedure that opens the form):

For Each ctl In [Forms]![frmInstrumentMalfunctionReport].Controls
If ctl.Tag = "On" Then
ctl.Enabled = True
ctl.Locked = False
ElseIf ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.Enabled = False
ctl.Locked = True
End If
Next ctl

Thanks so much for the help . . . and have a star to add to your firmament!
Tru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top