C
CNA527
I am trying to write a piece of code that I can re-use on differnet forms.
The code locks all the textbox fields in a form so that a user can not edit
a record unless they click a command button called Edit. I also have a
separate piece of code (gUnlockFields) that reverses the changes by the code
below. The code below exists in a module. The code works fine when called
from the OnClick event of a command button. However, I would like this
piece of code to run when a form is opened by the user but I get an error
message because I am using "Screen.ActiveForm". How can I modify the code
below so that it will execute when the form is opened (or opening)?
Sub gLockFields()
On Error GoTo Err_gLockFields
Dim frm As Form
Dim ctl As Control
Dim intI As Integer, intCanEdit As Integer
Const conWhite = 16777215
Set frm = Screen.ActiveForm
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acTextBox
.SpecialEffect = acEffectNormal
.Enabled = True
.Locked = False
.BackColor = conWhite
End Select
End With
Next ctl
Exit_gLockFields:
Exit Sub
Err_gLockFields:
MsgBox Err.Description
Resume Exit_gLockFields
End Sub
AA
The code locks all the textbox fields in a form so that a user can not edit
a record unless they click a command button called Edit. I also have a
separate piece of code (gUnlockFields) that reverses the changes by the code
below. The code below exists in a module. The code works fine when called
from the OnClick event of a command button. However, I would like this
piece of code to run when a form is opened by the user but I get an error
message because I am using "Screen.ActiveForm". How can I modify the code
below so that it will execute when the form is opened (or opening)?
Sub gLockFields()
On Error GoTo Err_gLockFields
Dim frm As Form
Dim ctl As Control
Dim intI As Integer, intCanEdit As Integer
Const conWhite = 16777215
Set frm = Screen.ActiveForm
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acTextBox
.SpecialEffect = acEffectNormal
.Enabled = True
.Locked = False
.BackColor = conWhite
End Select
End With
Next ctl
Exit_gLockFields:
Exit Sub
Err_gLockFields:
MsgBox Err.Description
Resume Exit_gLockFields
End Sub
AA