setfocus from subfrom

B

beovidius

Hi all,

I'm looping with the same problem:


After saving user entries from SubForm1, I need to hide it.

I found many posts talking about the SetFocus requirements.

So, I tried many different methods, none are working, but on a new test
form+subform (works like a charm)

' CODE from the SubForm1

Forms!MAINfrom.SetFocus 'First, I need to send the focus to MAINform
Forms!MAINfrom.NOOP.SetFocus 'NOOP is a textbox located on the MAINform

Forms![MAINfrom]![SubForm1].Form.Visible = False 'then theatrically, I can
hide the Subform1

AXS keeps saying : "Axs can't move to the control NOOP" + fix AND THEN " You
can't hide the control that has the focus "

The parent method also returns an error "can't move focus"

Any idea would be appreciated,

Thx,

Beo
 
B

beovidius

theatrically = theoretically

Should I mention this is under AXS2003 and the event fired by user click on
an Exit_button
 
B

BruceM

Please refer to it as Access. I figured that out after a little while, but
I still don't know what you mean by "+ fix AND THEN ".

Make sure the control NOOP is different than the field name, and set the
focus to the control:
Me.Parent.txtNOOP.SetFocus

In the Got Focus event of txtNOOP:
Me.SubformControlName.Visible = False

This will make the subform invisible whenever you click or tab into txtNOOP.
If you want to avoid that, you can declare a Boolean in the Declarations
section of the form's code module:
Public blnYourBoolean as Boolean
and set it to False when clicking the subform button that sets the focus to
txtNOOP. The GotFocus event for txtNOOP could test for the Boolean:
If blnYourBoolean = False Then
Me.SubformControlName.Visible = False
End If

Set it to True in the form's Current event.

I don't know exactly what you need to do, so this may not be the exact
solution you need, but the point is that the Boolean can be used as a test
before running code to hide or show the subform.
 
B

beovidius

BruceM said:
Please refer to it as Access. I figured that out after a little while, but
I still don't know what you mean by "+ fix AND THEN ".

The focus problem was fixed, then stops on Exec on the hiding(.visible = 0),
After many try, but now, I can't find back the right expression that
correctly set the focus to NOOP.
Make sure the control NOOP is different than the field name, and set the
focus to the control:
Me.Parent.txtNOOP.SetFocus

NOOP is just a loosy control(text box) on the main form, with the only
purpose to receive focus from any subforms, I need to hide.

the expression: Me.Parent.Ctrl.SetFocus doesn't work on ANY of my Frm.


In the Got Focus event of txtNOOP:
Me.SubformControlName.Visible = False

I understand the technique you are proposing and I will be able to implement
it as soon as I will understand why NOOP doesn't receive the focus anymore.
This will make the subform invisible whenever you click or tab into txtNOOP.

ok

Thank you Bruce, for your quick answer,


Regards,

Beo
 
B

beovidius

I found the cause, not the reason.

My exit button was generated programmatically. Even being clickable/visible,
it does not send correctly the focus to the NOOP control (still, don't know
why!)

Calling the "hide subform" after "set focus" is now working fine from a
"fresh new button" call.

Many thanks for your help,

Best regards,

Beo
 
B

BruceM

If you click through the error, does the focus go to NOOP? Is there any
code in the form's Got Focus event (or any other event) that set's the focus
to a control other than NOOP, or otherwise prevents the SetFocus in the
subform command button from working?
 
B

BruceM

I replied before I noticed this reply. Glad to hear you got it working.
Sometimes starting over with a new control and new code solves problems such
as you describe. It may be time to export everything to a new, blank
database.
 
B

beovidius via AccessMonster.com

BruceM said:
If you click through the error, does the focus go to NOOP? Is there any
code in the form's Got Focus event (or any other event) that set's the focus
to a control other than NOOP, or otherwise prevents the SetFocus in the
subform command button from working?

No, setfocus only returned an error, started working when I rebuild a new
form with all the same controls et fonctions.

Since I implement your workaround, it's working okay.

Thx again for your help,

Beo
 
B

beovidius via AccessMonster.com

The problem is occuring again, with the same call working yesterday, nothing
has been changed.
(don't know why !!)
The subfrm can not access the NOOP located on the top form.
 

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