Disable Multiple Fields at the same time

penfold1992

Registered User.
Local time
Today, 20:40
Joined
Nov 22, 2012
Messages
169
I want to incorperate a button that locks a certain portion of my form but my form is still quite long...

Is there a way which I can lock multiple fields at once or do i have to do:

Code:
Field1.Enabled = False
Field2.Enabled = False
Field3.Enabled = False
Field4.Enabled = False

and so on...
 
If you can associate the button with control names then you can write code to loop through..
 

Yep, this worked, I finished with:

Code:
Dim KeyContent As Variant
Dim Var
 
KeyContent = Array(Me.Field1,Me.Field2,Me.Field3......)
 
If Me.RecNo.Enabled = True Then
    For Each Var In KeyContent
        Var.Enabled = False
        Var.Locked = True
        Var.BackColor = RGB(217, 217, 217)
    Next Var
Else
    For Each Var In KeyContent
        Var.Enabled = True
        Var.Locked = False
        Var.BackColor = RGB(255, 255, 255)
    Next Var
End If

however, I have a "Dim Var" in this and im not sure what that means...
I thought you had to assign the variable to a data type ie Dim Var As String or Dim Var As Varient. What happens if you dont assign its data type?
 
I thought you had to assign the variable to a data type ie Dim Var As String or Dim Var As Variant.
You should, the best programming practice.. To declare all variables with its associated type..
What happens if you dont assign its data type?
If the variable is not assigned any type, it defaults it to Variant type..
 

Users who are viewing this thread

Back
Top Bottom