Lock all Controls on a Tab?

Meltdown

Registered User.
Local time
Today, 10:20
Joined
Feb 25, 2002
Messages
472
Hi all,

The following code will lock all controls on a form, but what I want is to lock all controls on a particular TAB, leaving the controls on other TABs enabled, does anyone know how to do that?

PHP:
 Dim c As Control

     For Each c In Me.Controls

                          c.Locked = True

    Next c

    Set c = Nothing
 
If it is a particular tab on a particular field, put the code in the On Lost Focus event of that field....and then unlock the controls on your desired field in the On Got Focus event.
 
First off, if you use the code above, and you have controls on your form that can't be locked, such as labels, your code will bomb. You need to either handle the error or make sure that your code only looks at controls that can be locked. The code below does this.

Code:
For Each c In Me.Controls
    If (TypeOf c Is TextBox) Or (TypeOf c Is ComboBox) Then

There is no native Access way of telling which controls lie on a given Tabbed Page, so you'll have to do this. In Form Design View, select all of the controls you want to lock, then goto Properties - Other and in the Property box labeled Tag enter LockCtrl. Then in the appropriate event
Code:
Dim ctrl As Control

For Each ctrl In Me.Controls
    If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then
    
       If ctrl.Tag = "LockCtrl" Then
         ctrl.Locked = True
       End If

    End If
 Next
Now only the controls tagged will be locked. In point of fact, if you're careful to only "tag" controls that have the Locked property, you could actuall omit the

If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then...End If

construct in this case, but it does no harm here, and you really should get used to doing it.
 
Last edited:
Thanks for the replies,

missinglinq, thanks for the code, that seems to work fine, much appreciated.

Regards
Melt
 
If it is a particular tab on a particular field, put the code in the On Lost Focus event of that field....and then unlock the controls on your desired field in the On Got Focus event.
As David Letterman frequently says "WHAT?"

Tabs aren't on fields! Fields (or more correctly, Controls) reside on Tabs. Fields reside in Tables, Controls reside in Forms.

And what good would it do to lock a textbox, if you're going to unlock the textbox when the user moves to it?
 
Simple Software Solutions

Only scanned through these threads but it seemed obvious to me that if you wanted to lock all the controls on a specific tab page on a tab control why not set the tab page to enabled = False and Locked = True. Or have I missed something?


CodeMaster::cool:
 
why not set the tab page to enabled = False and Locked = True. CodeMaster::cool:

No reason at all, CodeMaster! Actually, I'd never thought about individual pages having these properties, since they aren't controls, but rather parts of a control. In point of fact, they don't have a Locked Property, but they do have the Enabled Property, and it works handsomely in this particular situation!

Since the Index for Tabbed Pages is Zero-based, the syntax in VBA would be

First Page:
Me.TabCtl0.Pages(0).Enabled = False

Second Page
Me.TabCtl0.Pages(1).Enabled = False

and so forth.

Good deal, CodeMaster!
 
Simple Software Solutions

As stated, this was an off the cuff suggestion. I knew there was an enabled setting, and on the general concensis that if there is an enabled property there is usually a locked property I included this in my post without first checking it.

At present I am in VB mode using custom ocx controls that far exceed the limitiations of Access controls and as such tend to relate to their properties by mistake.

David.
 

Users who are viewing this thread

Back
Top Bottom