Form / Subform Reference Error

  • Thread starter Charles D Clayton Jr
  • Start date
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
 
D

david

Can you clarify where your code is placed in your
database? Is it in the form itself, or in a Module? If
in the form itself (which if it is not there, you might
consider moving it there, but not understanding all of
what you are working on makes this difficult to
recommend) then instead of using

Forms!frmBlahBlahBlah.Control

use

Me.Control

If however, the code is being referrenced from a Module,
you might need to redefine where the code is pointing
to. The problem when using a Subform sometimes is when
the Name of the Subform is the same as the
ControlSource. On your mainform, make sure to change the
Name property of the Subform, then you can point to the
controls in the Subform using

Forms!frmMain!NameOfSubform.ctlControl

Not sure if any of this will help, but good luck!
-----Original Message-----
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, _
 
C

Charles D Clayton Jr

Hopefully this will clarify things a bit. I have a parent form
"MainForm_WeeklyProgress" and a subform "subWeekly_Hrs" On the subform
is a command button that opens another form that asks for a password.
If the password is correct, then the password form closes and some
controls are unhidden on the subform. When I take the form
"subweekly_Hrs" and do not make it a subform, then I can get
everything to work properly. When I make is a subform, then I have
problems.

The command button has code behind it and it works fine. The function
"ShowControlGroup_Forms" is in its own module and it works fine (at
least when "subweekly_hrs" is the only form open" It is the password
form that is giving me problems. The code behind it only does three
things: Check the password, if correct, then close the password form
and then execute the function "ShowControlGroup_Forms", if incorrect,
then show warning page, if three times incorrect, then close database.

When "subweekly_hrs" is the only form, then your suggestion to use
"Me" keyword would work fine (which is exactly how I do it). But when
I make it a subform, then I cannot get the references to work. I
tried
Me,
subweekly_Hrs,
subweekly_hrs.Form,
MainForm_WeeklyProgress!subweekly_hrs,
MainForm_WeeklyProgress.subweekly_hrs,
MainForm_WeeklyProgress.subweekly_hrs.Form

I am out of ideas on how to refer to the subform.

I do appreciate your time,

Charles D Clayton Jr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top