locking all fields inside a form tab (1 Viewer)

megatronixs

Registered User.
Local time
Today, 10:09
Joined
Aug 17, 2012
Messages
719
Hi all,

Is there a way to lock all fields or grey them out inside a tab in the form?
I have done this once with vba, but needed to do this for all the fields (and there are over 40 in it).
Any ideas are welcome.

Greetings.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:09
Joined
Feb 19, 2013
Messages
16,601
for all the controls on the tab put something like 'intab' in tag property (you can select all the tabs and do it in one go)

then loop through the controls referencing the tag property

Code:
dim ctrl as control
for each ctrl in me.controls
    ctrl.enabled=ctrl.tag<>"intab"
next ctrl
 

megatronixs

Registered User.
Local time
Today, 10:09
Joined
Aug 17, 2012
Messages
719
Hi,

Thanks a lot, will give start using it right away. This for sure takes a lot of writting so much code :)

Greetings.
 

megatronixs

Registered User.
Local time
Today, 10:09
Joined
Aug 17, 2012
Messages
719
hi,

I don't get it to work. I should have mentioned that if a field has the value "Exit" then those fields should be locked, or greyed out.

I thried this code (in the form open code), but then the form does not open:
Code:
If Me.Status = "Exit" Then
Dim ctrl As Control
For Each ctrl In Me.Controls
    ctrl.Enabled = ctrl.Tag <> "intab"
Next ctrl
End If
any idea if I did something wrong?

Greetings.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:09
Joined
Feb 19, 2013
Messages
16,601
try the current event or load event - the data is not loaded in time for the open event.

google 'access form events' to find the order events occur and what happens for each event
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:09
Joined
Feb 28, 2001
Messages
27,122
If you want to block all edits on a particular form tab in one action, it would depend on what is on the rest of the form.

In the simplest case, the entire form is tabbed (i.e. when that tab is selected, there is no control on the form that is not on the tab.) In that case, play with the form's AllowEdits and other "Allow" properties. You can still change to another tab, and there are ways to know which tab is "up" at the moment. So let's say that the design is such that if tab A has control X clicked, then nothing on tab B can be altered. You could make the tab-click event diddle with the Allowxxx options when tab B comes up, and diddle them back to normal when tab A comes up.

The only other way I know to do what you just requested would be (a) manually make a definitive list of things to be diddled and write a VBA subroutine to implement that, or (b) make a loop using the "For all controlX in Me.Controls" enumeration method and inside that loop, if the control is of the type you want to diddle, then diddle it.
 

megatronixs

Registered User.
Local time
Today, 10:09
Joined
Aug 17, 2012
Messages
719
Hi all,

I finally managed. It was simpler then expected :)
There was already a full list of all the controls in one of the modules, so I just copy pasted them and I could use that list with the controls enabled or disabled.

Thank you all for you help.

Greetings.
 

Users who are viewing this thread

Top Bottom