Passing form name

  • Follow


I found this code (EnableFormControls) in the forum to enable/disable 
controls on a form but I'm having trouble setting the variable 'frmAny' and 
passing it to the sub EnableFormControls.  What am I doing wrong?  

Sub EnableFormControls(frmAny As Form, _
                           strControlSkip As String, _
                           Optional tfEnable As Boolean = True)
Dim ctlAny As Control
   On Error GoTo ERROR_Handler
   frmAny(strControlSkip).SetFocus
   For Each ctlAny In frmAny.Controls
      If ctlAny.Name <> strControlSkip Then
         Select Case ctlAny.ControlType
            Case acCheckBox, acComboBox, acCommandButton _
                 , acListBox, acOptionGroup, acSubform _
                 , acTextBox, acToggleButton
            ctlAny.Enabled = tfEnable
         End Select
      End If
   Next ctlAny
   Exit Sub

ERROR_Handler:
   If Err.Number = 2164 Then
      Resume Next
   Else
      MsgBox Err.Number & ": " & Err.Description, , _
      "Error in EnableFormControls"
   End If
End Sub

Private Sub Command1_Click()
Dim frmAny As Form
Dim strControlSkip As String
Dim tfEnable As Boolean


frmAny = Form2
strControlSkip = "Text2"
tfEnable = False

EnableFormControls frmAny, strControlSkip, tfEnable
End Sub

0
Reply Utf 2/16/2010 11:56:01 PM

"Pastor Del" <PastorDel@discussions.microsoft.com> wrote in message 
news:6C2693D5-769E-493E-807E-9C49648E7156@microsoft.com...
>I found this code (EnableFormControls) in the forum to enable/disable
> controls on a form but I'm having trouble setting the variable 'frmAny' 
> and
> passing it to the sub EnableFormControls.  What am I doing wrong?
>
> Sub EnableFormControls(frmAny As Form, _
>                           strControlSkip As String, _
>                           Optional tfEnable As Boolean = True)
> Dim ctlAny As Control
>   On Error GoTo ERROR_Handler
>   frmAny(strControlSkip).SetFocus
>   For Each ctlAny In frmAny.Controls
>      If ctlAny.Name <> strControlSkip Then
>         Select Case ctlAny.ControlType
>            Case acCheckBox, acComboBox, acCommandButton _
>                 , acListBox, acOptionGroup, acSubform _
>                 , acTextBox, acToggleButton
>            ctlAny.Enabled = tfEnable
>         End Select
>      End If
>   Next ctlAny
>   Exit Sub
>
> ERROR_Handler:
>   If Err.Number = 2164 Then
>      Resume Next
>   Else
>      MsgBox Err.Number & ": " & Err.Description, , _
>      "Error in EnableFormControls"
>   End If
> End Sub
>
> Private Sub Command1_Click()
> Dim frmAny As Form
> Dim strControlSkip As String
> Dim tfEnable As Boolean
>
>
> frmAny = Form2
> strControlSkip = "Text2"
> tfEnable = False
>
> EnableFormControls frmAny, strControlSkip, tfEnable
> End Sub
>

First off, the form must be open for this code to work. Also you need to 
reference the form via the Forms collection, like this:

frmAny = Forms!Form2


0
Reply Stuart 2/17/2010 12:14:54 AM

See if this helps. Instead of passing it as a form, I suggest passing the 
form name as string:

Sub EnableFormControls(strFrmAny As string, _
   strControlSkip As String, _
   Optional tfEnable As Boolean = True)
   
   Dim ctlAny As Control
   On Error GoTo ERROR_Handler

   Forms(strFrmAny).(strControlSkip).SetFocus

   For Each ctlAny In Forms(strFrmAny).Controls
      If ctlAny.Name <> strControlSkip Then
         Select Case ctlAny.ControlType
	    Case acCheckBox, acComboBox, acCommandButton, _
	         acListBox, acOptionGroup, acSubform, _
	         acTextBox, acToggleButton
		 ctlAny.Enabled = tfEnable  
         End Select
      End If
   Next ctlAny

Exit Sub

ERROR_Handler:
   If Err.Number = 2164 Then
      Resume Next
   Else
      MsgBox Err.Number & ": " & Err.Description, , _
      "Error in EnableFormControls"
   End If
End Sub

Private Sub Command1_Click()
   Dim strFrmAny As string
   Dim strControlSkip As String
   Dim tfEnable As Boolean


   strFrmAny = "frmAny"
   strControlSkip = "Text2"
   tfEnable = False

   EnableFormControls strFrmAny, strControlSkip, tfEnable

End Sub


"Pastor Del" wrote:

> I found this code (EnableFormControls) in the forum to enable/disable 
> controls on a form but I'm having trouble setting the variable 'frmAny' and 
> passing it to the sub EnableFormControls.  What am I doing wrong?  
> 
> Sub EnableFormControls(frmAny As Form, _
>                            strControlSkip As String, _
>                            Optional tfEnable As Boolean = True)
> Dim ctlAny As Control
>    On Error GoTo ERROR_Handler
>    frmAny(strControlSkip).SetFocus
>    For Each ctlAny In frmAny.Controls
>       If ctlAny.Name <> strControlSkip Then
>          Select Case ctlAny.ControlType
>             Case acCheckBox, acComboBox, acCommandButton _
>                  , acListBox, acOptionGroup, acSubform _
>                  , acTextBox, acToggleButton
>             ctlAny.Enabled = tfEnable
>          End Select
>       End If
>    Next ctlAny
>    Exit Sub
> 
> ERROR_Handler:
>    If Err.Number = 2164 Then
>       Resume Next
>    Else
>       MsgBox Err.Number & ": " & Err.Description, , _
>       "Error in EnableFormControls"
>    End If
> End Sub
> 
> Private Sub Command1_Click()
> Dim frmAny As Form
> Dim strControlSkip As String
> Dim tfEnable As Boolean
> 
> 
> frmAny = Form2
> strControlSkip = "Text2"
> tfEnable = False
> 
> EnableFormControls frmAny, strControlSkip, tfEnable
> End Sub
> 
0
Reply Utf 2/17/2010 4:33:01 AM

You could also try: -
frmAny = Me

-- 
A nod is as good as a wink to a blind horse.


"Pastor Del" wrote:

> I found this code (EnableFormControls) in the forum to enable/disable 
> controls on a form but I'm having trouble setting the variable 'frmAny' and 
> passing it to the sub EnableFormControls.  What am I doing wrong?  
> 
> Sub EnableFormControls(frmAny As Form, _
>                            strControlSkip As String, _
>                            Optional tfEnable As Boolean = True)
> Dim ctlAny As Control
>    On Error GoTo ERROR_Handler
>    frmAny(strControlSkip).SetFocus
>    For Each ctlAny In frmAny.Controls
>       If ctlAny.Name <> strControlSkip Then
>          Select Case ctlAny.ControlType
>             Case acCheckBox, acComboBox, acCommandButton _
>                  , acListBox, acOptionGroup, acSubform _
>                  , acTextBox, acToggleButton
>             ctlAny.Enabled = tfEnable
>          End Select
>       End If
>    Next ctlAny
>    Exit Sub
> 
> ERROR_Handler:
>    If Err.Number = 2164 Then
>       Resume Next
>    Else
>       MsgBox Err.Number & ": " & Err.Description, , _
>       "Error in EnableFormControls"
>    End If
> End Sub
> 
> Private Sub Command1_Click()
> Dim frmAny As Form
> Dim strControlSkip As String
> Dim tfEnable As Boolean
> 
> 
> frmAny = Form2
> strControlSkip = "Text2"
> tfEnable = False
> 
> EnableFormControls frmAny, strControlSkip, tfEnable
> End Sub
> 
0
Reply Utf 2/17/2010 6:01:02 AM

I tried 'frmAny = Me' without success.  DrGUI suggests that I try passing the 
name as a string.  I'll probably go that way because I know I can pass a 
string, but for the sake of greater understanding I'd like to know why I 
can't pass it as a form.  Any ideas?

"ChrisO" wrote:

> You could also try: -
> frmAny = Me
> 
> -- 
> A nod is as good as a wink to a blind horse.
> 
> 
> "Pastor Del" wrote:
> 
> > I found this code (EnableFormControls) in the forum to enable/disable 
> > controls on a form but I'm having trouble setting the variable 'frmAny' and 
> > passing it to the sub EnableFormControls.  What am I doing wrong?  
> > 
> > Sub EnableFormControls(frmAny As Form, _
> >                            strControlSkip As String, _
> >                            Optional tfEnable As Boolean = True)
> > Dim ctlAny As Control
> >    On Error GoTo ERROR_Handler
> >    frmAny(strControlSkip).SetFocus
> >    For Each ctlAny In frmAny.Controls
> >       If ctlAny.Name <> strControlSkip Then
> >          Select Case ctlAny.ControlType
> >             Case acCheckBox, acComboBox, acCommandButton _
> >                  , acListBox, acOptionGroup, acSubform _
> >                  , acTextBox, acToggleButton
> >             ctlAny.Enabled = tfEnable
> >          End Select
> >       End If
> >    Next ctlAny
> >    Exit Sub
> > 
> > ERROR_Handler:
> >    If Err.Number = 2164 Then
> >       Resume Next
> >    Else
> >       MsgBox Err.Number & ": " & Err.Description, , _
> >       "Error in EnableFormControls"
> >    End If
> > End Sub
> > 
> > Private Sub Command1_Click()
> > Dim frmAny As Form
> > Dim strControlSkip As String
> > Dim tfEnable As Boolean
> > 
> > 
> > frmAny = Form2
> > strControlSkip = "Text2"
> > tfEnable = False
> > 
> > EnableFormControls frmAny, strControlSkip, tfEnable
> > End Sub
> > 
0
Reply Utf 2/17/2010 5:58:02 PM

The form was open and I tried 'frmAny = Forms!Form2' without success.  DrGUI 
suggests that I try passing the name as a string.  I'll probably go that way 
because I know I can pass a string, but for the sake of greater understanding 
I'd like to know why I can't pass it as a form.  Any ideas?

"Stuart McCall" wrote:

> "Pastor Del" <PastorDel@discussions.microsoft.com> wrote in message 
> news:6C2693D5-769E-493E-807E-9C49648E7156@microsoft.com...
> >I found this code (EnableFormControls) in the forum to enable/disable
> > controls on a form but I'm having trouble setting the variable 'frmAny' 
> > and
> > passing it to the sub EnableFormControls.  What am I doing wrong?
> >
> > Sub EnableFormControls(frmAny As Form, _
> >                           strControlSkip As String, _
> >                           Optional tfEnable As Boolean = True)
> > Dim ctlAny As Control
> >   On Error GoTo ERROR_Handler
> >   frmAny(strControlSkip).SetFocus
> >   For Each ctlAny In frmAny.Controls
> >      If ctlAny.Name <> strControlSkip Then
> >         Select Case ctlAny.ControlType
> >            Case acCheckBox, acComboBox, acCommandButton _
> >                 , acListBox, acOptionGroup, acSubform _
> >                 , acTextBox, acToggleButton
> >            ctlAny.Enabled = tfEnable
> >         End Select
> >      End If
> >   Next ctlAny
> >   Exit Sub
> >
> > ERROR_Handler:
> >   If Err.Number = 2164 Then
> >      Resume Next
> >   Else
> >      MsgBox Err.Number & ": " & Err.Description, , _
> >      "Error in EnableFormControls"
> >   End If
> > End Sub
> >
> > Private Sub Command1_Click()
> > Dim frmAny As Form
> > Dim strControlSkip As String
> > Dim tfEnable As Boolean
> >
> >
> > frmAny = Form2
> > strControlSkip = "Text2"
> > tfEnable = False
> >
> > EnableFormControls frmAny, strControlSkip, tfEnable
> > End Sub
> >
> 
> First off, the form must be open for this code to work. Also you need to 
> reference the form via the Forms collection, like this:
> 
> frmAny = Forms!Form2
> 
> 
> .
> 
0
Reply Utf 2/17/2010 5:58:12 PM

Thanks, I'm sure I can pass the string & I'll probably do it this way.  But, 
can you explain why I couldn't pass it as a form, just for a better 
understanding of the beast?

"DrGUI" wrote:

> See if this helps. Instead of passing it as a form, I suggest passing the 
> form name as string:
> 
> Sub EnableFormControls(strFrmAny As string, _
>    strControlSkip As String, _
>    Optional tfEnable As Boolean = True)
>    
>    Dim ctlAny As Control
>    On Error GoTo ERROR_Handler
> 
>    Forms(strFrmAny).(strControlSkip).SetFocus
> 
>    For Each ctlAny In Forms(strFrmAny).Controls
>       If ctlAny.Name <> strControlSkip Then
>          Select Case ctlAny.ControlType
> 	    Case acCheckBox, acComboBox, acCommandButton, _
> 	         acListBox, acOptionGroup, acSubform, _
> 	         acTextBox, acToggleButton
> 		 ctlAny.Enabled = tfEnable  
>          End Select
>       End If
>    Next ctlAny
> 
> Exit Sub
> 
> ERROR_Handler:
>    If Err.Number = 2164 Then
>       Resume Next
>    Else
>       MsgBox Err.Number & ": " & Err.Description, , _
>       "Error in EnableFormControls"
>    End If
> End Sub
> 
> Private Sub Command1_Click()
>    Dim strFrmAny As string
>    Dim strControlSkip As String
>    Dim tfEnable As Boolean
> 
> 
>    strFrmAny = "frmAny"
>    strControlSkip = "Text2"
>    tfEnable = False
> 
>    EnableFormControls strFrmAny, strControlSkip, tfEnable
> 
> End Sub
> 
> 
> "Pastor Del" wrote:
> 
> > I found this code (EnableFormControls) in the forum to enable/disable 
> > controls on a form but I'm having trouble setting the variable 'frmAny' and 
> > passing it to the sub EnableFormControls.  What am I doing wrong?  
> > 
> > Sub EnableFormControls(frmAny As Form, _
> >                            strControlSkip As String, _
> >                            Optional tfEnable As Boolean = True)
> > Dim ctlAny As Control
> >    On Error GoTo ERROR_Handler
> >    frmAny(strControlSkip).SetFocus
> >    For Each ctlAny In frmAny.Controls
> >       If ctlAny.Name <> strControlSkip Then
> >          Select Case ctlAny.ControlType
> >             Case acCheckBox, acComboBox, acCommandButton _
> >                  , acListBox, acOptionGroup, acSubform _
> >                  , acTextBox, acToggleButton
> >             ctlAny.Enabled = tfEnable
> >          End Select
> >       End If
> >    Next ctlAny
> >    Exit Sub
> > 
> > ERROR_Handler:
> >    If Err.Number = 2164 Then
> >       Resume Next
> >    Else
> >       MsgBox Err.Number & ": " & Err.Description, , _
> >       "Error in EnableFormControls"
> >    End If
> > End Sub
> > 
> > Private Sub Command1_Click()
> > Dim frmAny As Form
> > Dim strControlSkip As String
> > Dim tfEnable As Boolean
> > 
> > 
> > frmAny = Form2
> > strControlSkip = "Text2"
> > tfEnable = False
> > 
> > EnableFormControls frmAny, strControlSkip, tfEnable
> > End Sub
> > 
0
Reply Utf 2/17/2010 6:00:01 PM

"Pastor Del" <PastorDel@discussions.microsoft.com> wrote in message 
news:6C39C27D-AD9A-45FF-934E-2CE83F30DF9C@microsoft.com...
> The form was open and I tried 'frmAny = Forms!Form2' without success.

My bad. Apologies. The line should read:

Set frmAny = Forms!Form2

When you're assigning an object, such as a form or report to a variable, you 
need to use the Set keyword.


0
Reply Stuart 2/17/2010 6:23:30 PM

>>I tried 'frmAny = Me' without success.<< is not very helpful in determining 
the problem. There may be other problems which are preventing it from 
working. However: -

Sub EnableFormControls(frmAny As Form, _
                           strControlSkip As String, _
                           Optional tfEnable As Boolean = True)

is expecting a reference (pointer) to be passed to it and Me should refer to 
the Form in which Private Sub Command1_Click() is running. Since Private Sub 
Command1_Click() is running, and doesn’t close the Form, then the Form must 
be open and Me must be valid.

I did not test Sub EnableFormControls at all but it does, as written, 
require a reference to a Form, not its name. If you are trying to use it on a 
sub Form from a parent Form then pass a reference to the sub Form with 
Me.YourSubFormControlNameGoesHere.Form. That also is untested.

More information about the failure is required, please.  

-- 
A nod is as good as a wink to a blind horse.


"Pastor Del" wrote:

> I tried 'frmAny = Me' without success.  DrGUI suggests that I try passing the 
> name as a string.  I'll probably go that way because I know I can pass a 
> string, but for the sake of greater understanding I'd like to know why I 
> can't pass it as a form.  Any ideas?
> 
> "ChrisO" wrote:
> 
> > You could also try: -
> > frmAny = Me
> > 
> > -- 
> > A nod is as good as a wink to a blind horse.
> > 
> > 
> > "Pastor Del" wrote:
> > 
> > > I found this code (EnableFormControls) in the forum to enable/disable 
> > > controls on a form but I'm having trouble setting the variable 'frmAny' and 
> > > passing it to the sub EnableFormControls.  What am I doing wrong?  
> > > 
> > > Sub EnableFormControls(frmAny As Form, _
> > >                            strControlSkip As String, _
> > >                            Optional tfEnable As Boolean = True)
> > > Dim ctlAny As Control
> > >    On Error GoTo ERROR_Handler
> > >    frmAny(strControlSkip).SetFocus
> > >    For Each ctlAny In frmAny.Controls
> > >       If ctlAny.Name <> strControlSkip Then
> > >          Select Case ctlAny.ControlType
> > >             Case acCheckBox, acComboBox, acCommandButton _
> > >                  , acListBox, acOptionGroup, acSubform _
> > >                  , acTextBox, acToggleButton
> > >             ctlAny.Enabled = tfEnable
> > >          End Select
> > >       End If
> > >    Next ctlAny
> > >    Exit Sub
> > > 
> > > ERROR_Handler:
> > >    If Err.Number = 2164 Then
> > >       Resume Next
> > >    Else
> > >       MsgBox Err.Number & ": " & Err.Description, , _
> > >       "Error in EnableFormControls"
> > >    End If
> > > End Sub
> > > 
> > > Private Sub Command1_Click()
> > > Dim frmAny As Form
> > > Dim strControlSkip As String
> > > Dim tfEnable As Boolean
> > > 
> > > 
> > > frmAny = Form2
> > > strControlSkip = "Text2"
> > > tfEnable = False
> > > 
> > > EnableFormControls frmAny, strControlSkip, tfEnable
> > > End Sub
> > > 
0
Reply Utf 2/17/2010 6:53:02 PM

Stuart pointed out my problem.  When you're assigning an object, such as a 
form or report to a variable, you need to use the Set keyword.  The code I 
initially posted works great when the Set keyword in used.

Thanks for you time and attention


"ChrisO" wrote:

> >>I tried 'frmAny = Me' without success.<< is not very helpful in determining 
> the problem. There may be other problems which are preventing it from 
> working. However: -
> 
> Sub EnableFormControls(frmAny As Form, _
>                            strControlSkip As String, _
>                            Optional tfEnable As Boolean = True)
> 
> is expecting a reference (pointer) to be passed to it and Me should refer to 
> the Form in which Private Sub Command1_Click() is running. Since Private Sub 
> Command1_Click() is running, and doesn’t close the Form, then the Form must 
> be open and Me must be valid.
> 
> I did not test Sub EnableFormControls at all but it does, as written, 
> require a reference to a Form, not its name. If you are trying to use it on a 
> sub Form from a parent Form then pass a reference to the sub Form with 
> Me.YourSubFormControlNameGoesHere.Form. That also is untested.
> 
> More information about the failure is required, please.  
> 
> -- 
> A nod is as good as a wink to a blind horse.
> 
> 
> "Pastor Del" wrote:
> 
> > I tried 'frmAny = Me' without success.  DrGUI suggests that I try passing the 
> > name as a string.  I'll probably go that way because I know I can pass a 
> > string, but for the sake of greater understanding I'd like to know why I 
> > can't pass it as a form.  Any ideas?
> > 
> > "ChrisO" wrote:
> > 
> > > You could also try: -
> > > frmAny = Me
> > > 
> > > -- 
> > > A nod is as good as a wink to a blind horse.
> > > 
> > > 
> > > "Pastor Del" wrote:
> > > 
> > > > I found this code (EnableFormControls) in the forum to enable/disable 
> > > > controls on a form but I'm having trouble setting the variable 'frmAny' and 
> > > > passing it to the sub EnableFormControls.  What am I doing wrong?  
> > > > 
> > > > Sub EnableFormControls(frmAny As Form, _
> > > >                            strControlSkip As String, _
> > > >                            Optional tfEnable As Boolean = True)
> > > > Dim ctlAny As Control
> > > >    On Error GoTo ERROR_Handler
> > > >    frmAny(strControlSkip).SetFocus
> > > >    For Each ctlAny In frmAny.Controls
> > > >       If ctlAny.Name <> strControlSkip Then
> > > >          Select Case ctlAny.ControlType
> > > >             Case acCheckBox, acComboBox, acCommandButton _
> > > >                  , acListBox, acOptionGroup, acSubform _
> > > >                  , acTextBox, acToggleButton
> > > >             ctlAny.Enabled = tfEnable
> > > >          End Select
> > > >       End If
> > > >    Next ctlAny
> > > >    Exit Sub
> > > > 
> > > > ERROR_Handler:
> > > >    If Err.Number = 2164 Then
> > > >       Resume Next
> > > >    Else
> > > >       MsgBox Err.Number & ": " & Err.Description, , _
> > > >       "Error in EnableFormControls"
> > > >    End If
> > > > End Sub
> > > > 
> > > > Private Sub Command1_Click()
> > > > Dim frmAny As Form
> > > > Dim strControlSkip As String
> > > > Dim tfEnable As Boolean
> > > > 
> > > > 
> > > > frmAny = Form2
> > > > strControlSkip = "Text2"
> > > > tfEnable = False
> > > > 
> > > > EnableFormControls frmAny, strControlSkip, tfEnable
> > > > End Sub
> > > > 
0
Reply Utf 2/17/2010 7:25:01 PM

Thanks, it works great with the Set keyword.  I'm self-taught and had not 
come across this kind of situation before.  Thanks again.

"Stuart McCall" wrote:

> "Pastor Del" <PastorDel@discussions.microsoft.com> wrote in message 
> news:6C39C27D-AD9A-45FF-934E-2CE83F30DF9C@microsoft.com...
> > The form was open and I tried 'frmAny = Forms!Form2' without success.
> 
> My bad. Apologies. The line should read:
> 
> Set frmAny = Forms!Form2
> 
> When you're assigning an object, such as a form or report to a variable, you 
> need to use the Set keyword.
> 
> 
> .
> 
0
Reply Utf 2/17/2010 7:27:01 PM

Yes, Stuart is correct and I should have tested the code.

As a matter of interest: -

Private Sub Command1_Click()
    Dim frmAny As Form
    Dim strControlSkip As String
    Dim tfEnable As Boolean
    
    Set frmAny = Me
    strControlSkip = "Text2"
    tfEnable = False

    EnableFormControls frmAny, strControlSkip, tfEnable
    
End Sub

can be reduced to: -

Private Sub Command1_Click()

    EnableFormControls Me, "Text2", False
    
End Sub

which removes the problem.

-- 
A nod is as good as a wink to a blind horse.


"Pastor Del" wrote:

> Stuart pointed out my problem.  When you're assigning an object, such as a 
> form or report to a variable, you need to use the Set keyword.  The code I 
> initially posted works great when the Set keyword in used.
> 
> Thanks for you time and attention
> 
> 
> "ChrisO" wrote:
> 
> > >>I tried 'frmAny = Me' without success.<< is not very helpful in determining 
> > the problem. There may be other problems which are preventing it from 
> > working. However: -
> > 
> > Sub EnableFormControls(frmAny As Form, _
> >                            strControlSkip As String, _
> >                            Optional tfEnable As Boolean = True)
> > 
> > is expecting a reference (pointer) to be passed to it and Me should refer to 
> > the Form in which Private Sub Command1_Click() is running. Since Private Sub 
> > Command1_Click() is running, and doesn’t close the Form, then the Form must 
> > be open and Me must be valid.
> > 
> > I did not test Sub EnableFormControls at all but it does, as written, 
> > require a reference to a Form, not its name. If you are trying to use it on a 
> > sub Form from a parent Form then pass a reference to the sub Form with 
> > Me.YourSubFormControlNameGoesHere.Form. That also is untested.
> > 
> > More information about the failure is required, please.  
> > 
> > -- 
> > A nod is as good as a wink to a blind horse.
> > 
> > 
> > "Pastor Del" wrote:
> > 
> > > I tried 'frmAny = Me' without success.  DrGUI suggests that I try passing the 
> > > name as a string.  I'll probably go that way because I know I can pass a 
> > > string, but for the sake of greater understanding I'd like to know why I 
> > > can't pass it as a form.  Any ideas?
> > > 
> > > "ChrisO" wrote:
> > > 
> > > > You could also try: -
> > > > frmAny = Me
> > > > 
> > > > -- 
> > > > A nod is as good as a wink to a blind horse.
> > > > 
> > > > 
> > > > "Pastor Del" wrote:
> > > > 
> > > > > I found this code (EnableFormControls) in the forum to enable/disable 
> > > > > controls on a form but I'm having trouble setting the variable 'frmAny' and 
> > > > > passing it to the sub EnableFormControls.  What am I doing wrong?  
> > > > > 
> > > > > Sub EnableFormControls(frmAny As Form, _
> > > > >                            strControlSkip As String, _
> > > > >                            Optional tfEnable As Boolean = True)
> > > > > Dim ctlAny As Control
> > > > >    On Error GoTo ERROR_Handler
> > > > >    frmAny(strControlSkip).SetFocus
> > > > >    For Each ctlAny In frmAny.Controls
> > > > >       If ctlAny.Name <> strControlSkip Then
> > > > >          Select Case ctlAny.ControlType
> > > > >             Case acCheckBox, acComboBox, acCommandButton _
> > > > >                  , acListBox, acOptionGroup, acSubform _
> > > > >                  , acTextBox, acToggleButton
> > > > >             ctlAny.Enabled = tfEnable
> > > > >          End Select
> > > > >       End If
> > > > >    Next ctlAny
> > > > >    Exit Sub
> > > > > 
> > > > > ERROR_Handler:
> > > > >    If Err.Number = 2164 Then
> > > > >       Resume Next
> > > > >    Else
> > > > >       MsgBox Err.Number & ": " & Err.Description, , _
> > > > >       "Error in EnableFormControls"
> > > > >    End If
> > > > > End Sub
> > > > > 
> > > > > Private Sub Command1_Click()
> > > > > Dim frmAny As Form
> > > > > Dim strControlSkip As String
> > > > > Dim tfEnable As Boolean
> > > > > 
> > > > > 
> > > > > frmAny = Form2
> > > > > strControlSkip = "Text2"
> > > > > tfEnable = False
> > > > > 
> > > > > EnableFormControls frmAny, strControlSkip, tfEnable
> > > > > End Sub
> > > > > 
0
Reply Utf 2/17/2010 9:00:01 PM

11 Replies
239 Views

(page loaded in 0.302 seconds)

Similiar Articles:































7/18/2012 10:26:55 PM


Reply: