Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

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

Open in new window

Avatar of Sandra Smith
Sandra Smith
Flag of United States of America image

ASKER

I did change the frmName.Name = strFormName to Set frmName = strFormName, but still does not recognize the form.
ASKER CERTIFIED SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That seems to work now.  Also I can use ME rather than having to explicitly name the form wherever it is used.

Sandra
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

Open in new window

Avatar of Jim Dettman (EE MVE)
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.