Objects, Forms, Me, ! , SetFocus etc.

D

dhstein

I'm having a specific problem that is probably due to my confusion about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last things I
want to do in the event are set the focus to the first field in form B and
make the current control in form A: Visible = false. I thought I could do it
in that order - that by setting the focus to the new control I could set the
current control to Visible = False but that doesn't work saying that you
can't hide a control that has the focus. So that's confusion number 1.
Confusion number 2 is I tried instead to set the focus to another control in
form A - so that I could set Visible = False on the control I'm trying to
hide. But I seem to have syntax problems because that's giving me errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific form?
Thanks if you can help me get less confused here.
 
D

Douglas J. Steele

To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're changing the
visibility of controls on that form.
 
D

dhstein

Doug,

Thanks for your help. That let me get it working. But I still have a
question. If I set the focus to a control on another form I still get an
error - that you can't hide a control that has the focus. I guess there is a
focus value maintained separately for each form. Is that correct?

See the code below:


This works:

cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:




'*********************************
This doesn't work :


cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

' Comment out the next line - and I get an error
'Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:



Douglas J. Steele said:
To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're changing the
visibility of controls on that form.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
I'm having a specific problem that is probably due to my confusion about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last things
I
want to do in the event are set the focus to the first field in form B and
make the current control in form A: Visible = false. I thought I could do
it
in that order - that by setting the focus to the new control I could set
the
current control to Visible = False but that doesn't work saying that you
can't hide a control that has the focus. So that's confusion number 1.
Confusion number 2 is I tried instead to set the focus to another control
in
form A - so that I could set Visible = False on the control I'm trying to
hide. But I seem to have syntax problems because that's giving me errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific form?
Thanks if you can help me get less confused here.
 
D

Douglas J. Steele

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

I don't see the point of the first SetFocus. Only one form can be active,
with only one control having focus.
Forms![MainMenu]![lblNewProduct].Visible = False

I'm assuming that txbProductName is the name of a text box, and
lblNewProduct is the label associated with that text box. Since the text box
has focus, you cannot hide its label.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
Doug,

Thanks for your help. That let me get it working. But I still have a
question. If I set the focus to a control on another form I still get an
error - that you can't hide a control that has the focus. I guess there
is a
focus value maintained separately for each form. Is that correct?

See the code below:


This works:

cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:




'*********************************
This doesn't work :


cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

' Comment out the next line - and I get an error
'Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:



Douglas J. Steele said:
To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're changing
the
visibility of controls on that form.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
I'm having a specific problem that is probably due to my confusion
about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last
things
I
want to do in the event are set the focus to the first field in form B
and
make the current control in form A: Visible = false. I thought I could
do
it
in that order - that by setting the focus to the new control I could
set
the
current control to Visible = False but that doesn't work saying that
you
can't hide a control that has the focus. So that's confusion number 1.
Confusion number 2 is I tried instead to set the focus to another
control
in
form A - so that I could set Visible = False on the control I'm trying
to
hide. But I seem to have syntax problems because that's giving me
errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific form?
Thanks if you can help me get less confused here.
 
D

dhstein

Doug - yes - that's my question as I don't see the point of the first
..SetFocus either - but without it, I get an error message that you can't hide
a form that has the focus. So it seems to me that there is one control that
has the focus for each form. And if I set the focus to the control on the
second form, the control on the first form still has the focus for that form
and therefore I can't set it's visible property to false.

Douglas J. Steele said:
Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

I don't see the point of the first SetFocus. Only one form can be active,
with only one control having focus.
Forms![MainMenu]![lblNewProduct].Visible = False

I'm assuming that txbProductName is the name of a text box, and
lblNewProduct is the label associated with that text box. Since the text box
has focus, you cannot hide its label.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
Doug,

Thanks for your help. That let me get it working. But I still have a
question. If I set the focus to a control on another form I still get an
error - that you can't hide a control that has the focus. I guess there
is a
focus value maintained separately for each form. Is that correct?

See the code below:


This works:

cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:




'*********************************
This doesn't work :


cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

' Comment out the next line - and I get an error
'Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:



Douglas J. Steele said:
To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're changing
the
visibility of controls on that form.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I'm having a specific problem that is probably due to my confusion
about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last
things
I
want to do in the event are set the focus to the first field in form B
and
make the current control in form A: Visible = false. I thought I could
do
it
in that order - that by setting the focus to the new control I could
set
the
current control to Visible = False but that doesn't work saying that
you
can't hide a control that has the focus. So that's confusion number 1.
Confusion number 2 is I tried instead to set the focus to another
control
in
form A - so that I could set Visible = False on the control I'm trying
to
hide. But I seem to have syntax problems because that's giving me
errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific form?
Thanks if you can help me get less confused here.
 
D

Douglas J. Steele

Okay, sorry but I didn't test before posting (plus I misread your code.)

Setting focus to a control on another form doesn't actually do anything.
It's just like you can have a current directory defined for each drive, but
the CurDir function will return the current directory for the current drive
only.

In order to change focus to a control on another form, you need to set focus
onto the other form first:

Forms![frmNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

In your existing code, even though you've got the statement

Forms![frmNewProduct]![txbProductName].SetFocus

since the code is running in cbxNewProduct_AfterUpdate, that means that
focus is still on cbxNewProduct. That's why you can't hide it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
Doug - yes - that's my question as I don't see the point of the first
.SetFocus either - but without it, I get an error message that you can't
hide
a form that has the focus. So it seems to me that there is one control
that
has the focus for each form. And if I set the focus to the control on the
second form, the control on the first form still has the focus for that
form
and therefore I can't set it's visible property to false.

Douglas J. Steele said:
Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

I don't see the point of the first SetFocus. Only one form can be active,
with only one control having focus.
Forms![MainMenu]![lblNewProduct].Visible = False

I'm assuming that txbProductName is the name of a text box, and
lblNewProduct is the label associated with that text box. Since the text
box
has focus, you cannot hide its label.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
Doug,

Thanks for your help. That let me get it working. But I still have a
question. If I set the focus to a control on another form I still get
an
error - that you can't hide a control that has the focus. I guess
there
is a
focus value maintained separately for each form. Is that correct?

See the code below:


This works:

cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:




'*********************************
This doesn't work :


cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

' Comment out the next line - and I get an error
'Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:



:

To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're
changing
the
visibility of controls on that form.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I'm having a specific problem that is probably due to my confusion
about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last
things
I
want to do in the event are set the focus to the first field in form
B
and
make the current control in form A: Visible = false. I thought I
could
do
it
in that order - that by setting the focus to the new control I could
set
the
current control to Visible = False but that doesn't work saying that
you
can't hide a control that has the focus. So that's confusion number
1.
Confusion number 2 is I tried instead to set the focus to another
control
in
form A - so that I could set Visible = False on the control I'm
trying
to
hide. But I seem to have syntax problems because that's giving me
errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific
form?
Thanks if you can help me get less confused here.
 
D

dhstein

Doug,

Thanks. That worked and even better, it helped me understand what's
going on.

Douglas J. Steele said:
Okay, sorry but I didn't test before posting (plus I misread your code.)

Setting focus to a control on another form doesn't actually do anything.
It's just like you can have a current directory defined for each drive, but
the CurDir function will return the current directory for the current drive
only.

In order to change focus to a control on another form, you need to set focus
onto the other form first:

Forms![frmNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

In your existing code, even though you've got the statement

Forms![frmNewProduct]![txbProductName].SetFocus

since the code is running in cbxNewProduct_AfterUpdate, that means that
focus is still on cbxNewProduct. That's why you can't hide it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dhstein said:
Doug - yes - that's my question as I don't see the point of the first
.SetFocus either - but without it, I get an error message that you can't
hide
a form that has the focus. So it seems to me that there is one control
that
has the focus for each form. And if I set the focus to the control on the
second form, the control on the first form still has the focus for that
form
and therefore I can't set it's visible property to false.

Douglas J. Steele said:
Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus

I don't see the point of the first SetFocus. Only one form can be active,
with only one control having focus.

Forms![MainMenu]![lblNewProduct].Visible = False

I'm assuming that txbProductName is the name of a text box, and
lblNewProduct is the label associated with that text box. Since the text
box
has focus, you cannot hide its label.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Doug,

Thanks for your help. That let me get it working. But I still have a
question. If I set the focus to a control on another form I still get
an
error - that you can't hide a control that has the focus. I guess
there
is a
focus value maintained separately for each form. Is that correct?

See the code below:


This works:

cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:




'*********************************
This doesn't work :


cbxNewProduct_AfterUpdate()


'other code here
' .....
' .....

' Comment out the next line - and I get an error
'Forms![MainMenu]![btnNewProduct].SetFocus
Forms![frmNewProduct]![txbProductName].SetFocus
Forms![MainMenu]![lblNewProduct].Visible = False
Forms![MainMenu]![cbxNewProduct].Visible = False

cbxNewProduct_AfterUpdate_Exit:



:

To set focus on a control, you'd use

Forms![NameOfForm]![NameOfControl].SetFocus

To hide a control, you'd use

Forms![NameOfForm]![NameOfControl].Visible = False

It's not necessary for the focus to be on the form when you're
changing
the
visibility of controls on that form.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I'm having a specific problem that is probably due to my confusion
about a
general problem.

Specifically, I'm opening form B from an event in Form A. The last
things
I
want to do in the event are set the focus to the first field in form
B
and
make the current control in form A: Visible = false. I thought I
could
do
it
in that order - that by setting the focus to the new control I could
set
the
current control to Visible = False but that doesn't work saying that
you
can't hide a control that has the focus. So that's confusion number
1.
Confusion number 2 is I tried instead to set the focus to another
control
in
form A - so that I could set Visible = False on the control I'm
trying
to
hide. But I seem to have syntax problems because that's giving me
errors
that it can't find that control - although it is definitely there.

So what is the syntax to specify a specific control on a specific
form?
Thanks if you can help me get less confused here.
 

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