C
Charles D Clayton Jr
A2K
Here is the situation. I have a mainform and a subform. On the subform
there is a command button that is password protected. This is done by
opening another form for a person to type the password. If they have
typed the correct password, then it will unhide a number of controls.
I use a function to hide/unhide controls. But I cannot get it to work
on this subform. If I treat the subform like a mainform, then I can
get the syntax correct and the commandbutton will unhide the controls
I want. But when I make is a subform on the mainform I cannot get it
to work correctly. Here is the code that works properly if it is a
mainform
Code:
--------------------------------------------------------------------------------
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Worker", False
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Manager", True
--------------------------------------------------------------------------------
The Function uses the tag value to hide or unhide a control. In this
case, "Worker" and "Manager" are the words that I put into the tag
value. The forms name is "subweekly_hrs" The mainform is
"MainForm_WeeklyProgress"
I have tried the following ways of referring to the subform and none
of them worked
Code:
--------------------------------------------------------------------------------
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress _
subWeekly_Hrs.Form, "Worker", False
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress _
subWeekly_Hrs.Form, "Manager", True
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress.subWeekly_Hrs,
"Worker", _ False
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress.subWeekly_Hrs, _
"Manager", True
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Worker", False
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Manager", True
ShowControlGroup_Forms subWeekly_Hrs.Form, "Worker", False
ShowControlGroup_Forms subWeekly_Hrs.Form, "Manager", True
--------------------------------------------------------------------------------
I looked on Dev Ashish's Website at that page on referring to controls
from subforms but it did not help
Does anybody have any suggestions?
Charles
PS - here is that function to Hide/Unhide if it will help
Code:
--------------------------------------------------------------------------------
Function ShowControlGroup_Forms( _
OnForm As Form, _
GroupName As String, _
Optional ShowOrHide As Boolean = True)
' Shows or hides a group of controls, as identified by the
' presence of <GroupName> in their Tag properties.
'
' Arguments:
' OnForm - A reference to the form object containing
' the controls
' GroupName - The "name" of the group; a string to look
' for in each control's Tag property
' ShowOrHide - True (the default) to show the controls;
' False to hide them.
On Error GoTo Err_ShowControlGroup
Dim ctl As Access.Control
Const conERR_CANT_HIDE = 2165
' Error number if control to be hidden has the focus
For Each ctl In OnForm.Controls
If ctl.Tag Like "*" & GroupName & "*" Then
ctl.Visible = ShowOrHide
End If
Next ctl
Exit_ShowControlGroup:
Exit FunctionErr_ShowControlGroup:
If Err.Number = conERR_CANT_HIDE Then
' If we can't hide this control because it has the
' focus, just skip it.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_ShowControlGroup
End If
End Function
Here is the situation. I have a mainform and a subform. On the subform
there is a command button that is password protected. This is done by
opening another form for a person to type the password. If they have
typed the correct password, then it will unhide a number of controls.
I use a function to hide/unhide controls. But I cannot get it to work
on this subform. If I treat the subform like a mainform, then I can
get the syntax correct and the commandbutton will unhide the controls
I want. But when I make is a subform on the mainform I cannot get it
to work correctly. Here is the code that works properly if it is a
mainform
Code:
--------------------------------------------------------------------------------
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Worker", False
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Manager", True
--------------------------------------------------------------------------------
The Function uses the tag value to hide or unhide a control. In this
case, "Worker" and "Manager" are the words that I put into the tag
value. The forms name is "subweekly_hrs" The mainform is
"MainForm_WeeklyProgress"
I have tried the following ways of referring to the subform and none
of them worked
Code:
--------------------------------------------------------------------------------
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress _
subWeekly_Hrs.Form, "Worker", False
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress _
subWeekly_Hrs.Form, "Manager", True
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress.subWeekly_Hrs,
"Worker", _ False
ShowControlGroup_Forms Forms!MainForm_WeeklyProgress.subWeekly_Hrs, _
"Manager", True
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Worker", False
ShowControlGroup_Forms Forms!subWeekly_Hrs, "Manager", True
ShowControlGroup_Forms subWeekly_Hrs.Form, "Worker", False
ShowControlGroup_Forms subWeekly_Hrs.Form, "Manager", True
--------------------------------------------------------------------------------
I looked on Dev Ashish's Website at that page on referring to controls
from subforms but it did not help
Does anybody have any suggestions?
Charles
PS - here is that function to Hide/Unhide if it will help
Code:
--------------------------------------------------------------------------------
Function ShowControlGroup_Forms( _
OnForm As Form, _
GroupName As String, _
Optional ShowOrHide As Boolean = True)
' Shows or hides a group of controls, as identified by the
' presence of <GroupName> in their Tag properties.
'
' Arguments:
' OnForm - A reference to the form object containing
' the controls
' GroupName - The "name" of the group; a string to look
' for in each control's Tag property
' ShowOrHide - True (the default) to show the controls;
' False to hide them.
On Error GoTo Err_ShowControlGroup
Dim ctl As Access.Control
Const conERR_CANT_HIDE = 2165
' Error number if control to be hidden has the focus
For Each ctl In OnForm.Controls
If ctl.Tag Like "*" & GroupName & "*" Then
ctl.Visible = ShowOrHide
End If
Next ctl
Exit_ShowControlGroup:
Exit FunctionErr_ShowControlGroup:
If Err.Number = conERR_CANT_HIDE Then
' If we can't hide this control because it has the
' focus, just skip it.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_ShowControlGroup
End If
End Function