Cycle through controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form which displays all the information of the records in a table.
I would like to set all the textbox's which display the info to enabled=false
and locked=true, until the user clicks an edit form button, which, after
entering a password or something, sets all the textboxes back to normal.
 
Set all the controls in Design view. In your command button On_Click event,
loop through the form's Controls collection:

Dim ctl as Control
Dim strPW as String
Const cstrPW = "YourPassword"

' Get password
strPW = InputBox("Enter password:","Password Required")

' If it matches the assigned constant, loop through controls
If strPW = cstrPW Then

For Each ctl in Me.Controls
' Check the control type to avoid an error if the controls does not
have an
' Enabled property.
If ctl.ControlType = acTextbox Then
With ctl
.Enabled = True
.Locked = False
End With
End If
Next ctl

Else
MsgBox "Incorrect password."
End If

Hope that helps.
Sprinks
 
Works great, thanks!


Sprinks said:
Set all the controls in Design view. In your command button On_Click event,
loop through the form's Controls collection:

Dim ctl as Control
Dim strPW as String
Const cstrPW = "YourPassword"

' Get password
strPW = InputBox("Enter password:","Password Required")

' If it matches the assigned constant, loop through controls
If strPW = cstrPW Then

For Each ctl in Me.Controls
' Check the control type to avoid an error if the controls does not
have an
' Enabled property.
If ctl.ControlType = acTextbox Then
With ctl
.Enabled = True
.Locked = False
End With
End If
Next ctl

Else
MsgBox "Incorrect password."
End If

Hope that helps.
Sprinks
 
Back
Top