?
Solved

Pass name of form to function

Posted on 2011-09-15
5
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 58
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

765 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