Locked and Enabled Properties

CanWest

Registered User.
Local time
Today, 16:07
Joined
Sep 15, 2006
Messages
272
Hello Everyone

I have a form that has close to 75 fields on it. These fields are spread out between several Tab controls and a few subforms. Here is my delima

I need to control the state of the Locked and Enabled properties based on a security level when the form is opened. I do know how to do this for a handfull of fields. I the past I have used something like this in the onLoad event


Code:
    If Forms!frm_LogonStorage!SecurityLevel > 40 Then
        Forms![frm_MainMenu]![sfrm_Clients].Form![FirstName].Locked = False
        Forms![frm_MainMenu]![sfrm_Clients].Form![FirstName].Enabled = True
        Forms![frm_MainMenu]![sfrm_Clients].Form![LastName].Locked = False
        Forms![frm_MainMenu]![sfrm_Clients].Form![LasttName].Enabled = True
    Else

        Forms![frm_MainMenu]![sfrm_Clients].Form![FirstName].Locked = Tru
        Forms![frm_MainMenu]![sfrm_Clients].Form![FirstName].Enabled = False
        Forms![frm_MainMenu]![sfrm_Clients].Form![LastName].Locked = True
        Forms![frm_MainMenu]![sfrm_Clients].Form![LasttName].Enabled = False
   Endif

What I want to know is there a better way to do this when I have so many fields to do. I thought about doing it to each of the subform and tab controls them selves but there are quite a few that I do not want to do this to.

Any ideas would be greatly appreciated.
 
Yep there is. Each of your controls has a property in the OTHER tab called TAG. I set this property for all the fields I want locked to "lock". Then in my code I loop through all controls where the tag value is "lock" and then lock the field

Code:
dim ctl as variant
 
for each ctl in me.controls
if ctl.tag = "lock" then
   ctl.locked = true
end if
 
This looks great, but if you have alot of fields will take a while to sent all Tags to "Lock". Is there a way to lock the whole form, or do I have to do each control?
 
Create a function with this code and name it something like "LockControls", then call it when you need it (like the On Load event of the form). To unlock the controls, then just create another function "UnlockControls" and change the = True to = False:

Code:
For Each txtbx In Me.Controls      'locks textboxes
        If TypeOf txtbx Is TextBox Then
            txtbx.Locked = True
            txtbx.BackColor = vbWhite
        End If
    Next
    
    For Each cb In Me.Controls           'locks combo boxes
        If TypeOf cbo Is ComboBox Then
            cbo.Locked = True
            cbo.BackColor = vbWhite
        End If
    Next

    For Each SubF In Me.Controls          'locks subforms
        If TypeOf SubF Is SubForm Then
            SubF.Locked = True
        End If
    Next

Dont forget to declare: Dim txtbx as Control, Dim cbo as Control, etc...

Also, the color is optional. I use it to let the user know that they can add or edit the fields when the color changes.
 
This looks great, I only want to lock the form when it is signed off by management. If I run this On_load it will lock all records, correct?

So it would be best to run this on Current i think.

Private Sub Form_Current()
If Me.SignedOff <> "" Then
Your code here
.
.
.

EndIf
 
@GT engineer = you can also just lock the Detail section of your form as long as you have navigation and other buttons that users need to navigate records in the header of footer of your form.
On current event of form
Code:
if me.signedoff <> "" then
me.section(acDetail).locked = true
else
me.section(acDetail).locked = false
end if
 
don;t worry about the time to update all your controls

it doesn't take long for all the controls to iterate

a handful of clock ticks per control - the total time taken to refresh the form's controls will be microseconds - you won't notice it "painting"
 

Users who are viewing this thread

Back
Top Bottom