Solved

Pass name of form to function

Posted on 2011-09-15
5
289 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
ID: 36544266
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
ID: 36544287
Public Function fntDisableControls(strFormName As Form)

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

Author Closing Comment

by:ssmith94015
ID: 36544306
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
ID: 36544310
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
ID: 36544345
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

910 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

23 Experts available now in Live!

Get 1:1 Help Now