[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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

0
ssmith94015
Asked:
ssmith94015
  • 3
1 Solution
 
ssmith94015Author Commented:
I did change the frmName.Name = strFormName to Set frmName = strFormName, but still does not recognize the form.
0
 
CluskittCommented:
Public Function fntDisableControls(strFormName As Form)

Send the form itself as a parameter, instead of the name.
0
 
ssmith94015Author Commented:
That seems to work now.  Also I can use ME rather than having to explicitly name the form wherever it is used.

Sandra
0
 
ssmith94015Author Commented:
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

0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
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.

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now