Solved

Pass name of form to function

Posted on 2011-09-15
5
288 Views
Last Modified: 2012-05-12
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
Comment
Question by:ssmith94015
  • 3
5 Comments
 

Author Comment

by:ssmith94015
Comment Utility
I did change the frmName.Name = strFormName to Set frmName = strFormName, but still does not recognize the form.
0
 
LVL 18

Accepted Solution

by:
Cluskitt earned 500 total points
Comment Utility
Public Function fntDisableControls(strFormName As Form)

Send the form itself as a parameter, instead of the name.
0
 

Author Closing Comment

by:ssmith94015
Comment Utility
That seems to work now.  Also I can use ME rather than having to explicitly name the form wherever it is used.

Sandra
0
 

Author Comment

by:ssmith94015
Comment Utility
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
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now