Make all controls invisible but few

latex88

Registered User.
Local time
Today, 10:10
Joined
Jul 10, 2003
Messages
198
So, I think I have a good routine to make all controls of a form invisible except a few, but I'm getting "You entered an expression that requires a form to be the active window." I've put the below code in On Open, On Load, On Activate, and still get the error with this line being highlighted,
Set frmCurrentForm = Screen.ActiveForm
Please help. I actually would like to use this in other forms too. Do I just make a public function?

Public Sub CloseAllControls()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm

Dim ctl As Control
Dim CurrentForm As Form
Set CurrentForm = Screen.ActiveForm

For Each ctl In CurrentForm.Controls
ctl.Visible = False
Next ctl
End Sub
 
If you are intending this code to execute in the context of the current form, could you simply refer to it as Me? Code executing on the current form may refer to itself as Me.

It appears to work:
Code:
Private Sub btnEnum_Click()
  On Error GoTo Err_btnEnum_Click

  Dim ctl As Access.Control

  For Each ctl In Me
    Debug.Print ctl.Name
  Next ctl

Exit_btnEnum_Click:
  Exit Sub

Err_btnEnum_Click:
  Call errorhandler_MsgBox("Form: Form_DateMath, Subroutine: btnEnum_Click()")
  Resume Exit_btnEnum_Click

End Sub
Immediate window output:
Code:
fldDateStart
Label1
fldDateEnd
Label3
fldDateDiff
Label5
btnCompute
fldWeeksLeft
Label7
fldETA
Label9
btnEnum
 
Last edited:
If you are intending this code to execute in the context of the current form, could you simply refer to it as Me? Code executing on the current form may refer to itself as Me.

Hi Michael,
Thanks for the quick response. I'm getting "Method or data member not found". Perhaps ActiveForm is not a good method? Sorry, my coding abilities are limited.
 
Please show your code.

I did not reference ActiveForm in the sample I provided. Please see my example again.

Strange. When I first saw your response, it didn't show the codes you provided. I just thought you want me to reference "me" in my code. I just tested your code. It works great for my needs. Thank you so much.
 
When I first saw your response, it didn't show the codes you provided.

I thought to come back to add the sample code, thus the confusion. It is good your problem is resolved. You are welcome.
 

Users who are viewing this thread

Back
Top Bottom