visible.no

  • Thread starter Thread starter Russ
  • Start date Start date
R

Russ

I have a form / subform. When I move off a combo box selection on the
subform by clicking on a list box on the main form, I would like the
combo box's visible value to change to no. I am having one whale of
a time accomplishing this. It seems for now that the combo box
doesn't lose the focus when I click in the list box because a message
pops up telling me I can't hide the control when it has the focus.
How can I get around this or is there another way?

Russ
 
You are correct, it still has the focus on the subform. In the code you are
using to hide it, move the focus to another control on the subform first.

xxx.OtherControl.SetFocus

"xxx" will vary depending on where you are doing the coding from, the main
form or the subform.
 
Wayne,

I guess I will have to learn some of the coding syntaxes and so forth
as I feel like a fish flopping on the bank. In code, I can't seem to
get how to designate a control that is on a different part of the
form. I get error messages when the code runs.

Runtime error 2460 MS Access can't find the form.
or
Runtime errror 424 Object required
or
Runtime error 2465 Object defined error

What does your xxx stand for in the example you sent?

Russ
 
Since you apparently were defining the combo box ok, I thought you already
had that part. The "xxx" was just a place holder for the form, but how you
define it depends on where you are defining it from. Your statement for the
combo box should be something like

xxx.cboMyCombo.Visible = False

What do you have in the Visible statement for the "xxx"? The same thing
should work with the SetFocus statement. If it still doesn't work, post the
statement you are using and where that statement is located.
 
It's taken me some tinkering with a siimilar db here at home, so when
I get to work I'll try it on the real thing. But this is what I coded
and it seems to work.

Private Sub DutyAssignSub_Exit(Cancel As Integer)
DutyAssignSub!SubCat.SetFocus
DutyAssignSub!MainCat.Visible = False
End Sub

I've put this code in the On Exit event of the subform. The
DutyAssignSub is the name of the subform, SubCat is a combo box on
that form, and MainCat is the combo I want to be hidden.

I would like to make my entire Detail section of the subform become
invisible when the subform is exited, but I've been unable to perform
that trick.

Russ
 
There are two items that you are working with here, a subform and a subform
control. The subform control is the control on the main form that holds the
subform. The subform itself is not "open" (i.e. Forms!NameOfSubform will
fail). To refer to the subform, the usual syntax would be
(Forms!NameOfMainForm!NameOfSubformControl.Form!NameOfControlOnSubform).
Now, of course, these are the long forms of the names. You can use Me to
refer to the form that the code is on, where appropriate (i.e.
Me!NameOfSubformControl.Form!NameOfControlOnSubform). By default, if you
just drag a form onto a main form for Access to make the subform then Access
will give the subform control the same name as the subform itself, which can
be confusing since these are actually two different objects.

It is possible to set the visible property of the subform control to false
to hide the entire subform. To get the name of the subform control, open the
main form in design mode, open the Properties sheet, and click on the
subform ONE time. Check the name in the Properties sheet. If you click on
the subform a second time, you will be in the subform itself and the
Properties sheet will show the name of the subform, not the name of the
control holding the subform.
 
The code I sent before was on the subform control On Exit event. I
didn't know it was called a subform control. Thanks for the little
lesson, I needed some guidance. What would be the code for me to hide
the detail section of the subform when exiting the subform control?
That would take care of all the controls in the subform so I wouldn't
have to code each one in individually.

Russ
 
Here is the code I'm working with:

Private Sub BLInputsub_Exit(Cancel As Integer)

Forms!BylawInputMain!AgreeSub.SetFocus
Forms!BylawInputMain!BLInputsub.Form!Bylaw.Visible = False

End Sub


BylawInputMain is the main form
BLINputsub is the subform that I want the control hidden
Bylaw is the control that I want to hide.
AgreeSub is another subform to conveniently set the focus on.

I've run the first line of code and it appears that the focus is on
the AgreeSub control since the cursor is in one of the fields on that
subform.

I added the second line of code and I get the message that "You can't
hide a control that has the focus" although I still see the blinking
cursor in a field of the subform control that I thought I assigned
focus to.

Russ
 
Here's a little more detail.

When I update the record with the combo box, then click on another
field in the subform, or the other subform all works ok. However,
when I click on the unbound listbox (which is set to "find a record on
my form...") I get the message about not being able to hide a control
while it has the focus.

Russ
 
Even though the subform may not have the focus any longer, the control may
still be the item on the subform that has the focus and will be the item
with the focus if you return to that subform. You need to move the focus to
another control on that subform before you can hide the control.
 
To hide the detail section try:

Forms!BylawInputMain!AgreeSub.Form.Detail.Visible = False

To hide the subform control try (and therefore the entire subform):

Forms!BylawInputMain!AgreeSub.Visible = False
 
Back
Top