Sandra Smith
asked on
Pass name of form to function
I am trying to adapt the attached code soit can be used by more than one form. However, I don't seem to get teh function to recognize the name of the form.
Public Function fntDisableControls(strFormName As String)
'If the claim is closed, lock the controls so changes cannot be made
Dim frmName As Form
frmName.Name = strFormName
'''frmName.CmdScans.SetFocus
Dim ctl As Control
For Each ctl In frmName.Controls
With ctl
Select Case .ControlType
Case acTextBox, acListBox, acComboBox
.Locked = True
.BackColor = 15461355
Case acCheckBox
.Enabled = False
.Locked = True
End Select
End With
Next ctl
'Me.SubFrmGLdata.Enabled = False
frmName.LblLocked.Visible = True
frmName.CmdUnlock.Visible = True
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That seems to work now. Also I can use ME rather than having to explicitly name the form wherever it is used.
Sandra
Sandra
ASKER
This is what I have now.
Public Function fntDisableControls(frmName As Form)
'If the claim is closed, lock the controls so changes cannot be made
frmName.CmdScans.SetFocus
Dim ctl As Control
For Each ctl In frmName.Controls
With ctl
Select Case .ControlType
Case acTextBox, acListBox, acComboBox
.Locked = True
.BackColor = 15461355
Case acCheckBox
.Enabled = False
.Locked = True
End Select
End With
Next ctl
'Me.SubFrmGLdata.Enabled = False
frmName.LblLocked.Visible = True
frmName.CmdUnlock.Visible = True
End Function
Just for clairty, I would change this:
Public Function fntDisableControls(frmName As Form)
to
Public Function fntDisableControls(frm As Form)
as your really not passing the name, but a form reference. frmName implies a string like you first had (which would have worked BTW, but a form reference is better by far).
Jim.
Public Function fntDisableControls(frmName
to
Public Function fntDisableControls(frm As Form)
as your really not passing the name, but a form reference. frmName implies a string like you first had (which would have worked BTW, but a form reference is better by far).
Jim.
ASKER