why does the GotFocus event fails?

G

Guest

Greetings
This relates to access 2000. I have a main form with two sub forms. One
subform (call it sbfrm1) has 4 text boxes while the other (call it sbfrm2)
has 3 text boxes. When I click a text box in sbfrm1 one of the text box in
sbfrm2 gets focus and its value is changed. The text box in sbfrm2 for which
the value changes gets the focus. I have an event procedure for GotFocus and
I have set the property OnGotFocus to EventProcedure. However the event does
not fire.

Any help will be appreciated
 
K

Ken Snell [MVP]

Are you thinking that the textbox on sbfrm2 gets focus just because its
value is changed? That is not correct. Focus must be set to that textbox by
code or by manually "clicking on" or "tabbing to" the field. Can you give us
more info, please?
 
G

Guest

Thanks for the response. Yes it was my feeling that once the value changes
the text box must have the focus. More so because the rest of the controls in
this form (sbfrm2) have their Enabled property set to "No" and thus cannot
have the focus (right?). So how should I go about explicitly setting the
focus to text box in question once the value has changed?. Once again thank
you for your response.

Farooq
 
K

Ken Snell [MVP]

Do you need to have the focus set to the textbox, or do you just want to run
the procedure that is attached to the textbox's GotFocus event?

To set focus from a control on one subform to a control on another subform,
you'll need three SetFocus actions:

Me.Parent.SomeControlNameOnMainForm.SetFocus
Me.Parent.SecondSubformControl.SetFocus
Me.Parent.SecondSubformControl.Form.ControlOnSecondSubform.SetFocus

SecondSubformControl is the name of the subform control that holds the
second subform.
 
G

Guest

Actually I just want to run the procedure attached to the textbox's GotFocus
event. While we are on this subject perhaps you can also explain why the
GotFocus procedure not run on the clicking the mouse in this textbox. The
rest of the controls on this subform had their Enabled property set to NO.
However on hitting the Enter key the procedure executed.

Thanks.
 
K

Ken Snell [MVP]

To run a procedure in a subform of the main form, change the subform's
procedure to Public, and then call it from the main form using this code:
Call Form_NameOfSubformForm_GotFocus()

(where NameOfSubformForm is the actual name of the form that is serving as
the subform).

I cannot say why the code isn't running when you click on the textbox --
one, I don't know what the code is supposed to do, and perhaps it doesn't do
anything?; two, it's possible that your first click isn't actually putting
focus on the textbox; three, your code may be attached to the AfterUpdate
event or some other event?

In short, as you've not posted any specific code or details about the actual
form's setup/contents, I'm just guessing here.
 
G

Guest

Thanks. My application is working correctly without running the GetFocus
procedure. I will definitely try out your two suggestions because I may need
these in the future. I am very new to access (this is my first application)
therefore a lot of things are new and for each answer I get I have more
questions. For example from which main form procedure should I run
Call Form_NameOfSubformForm_GotFocus()

Also I do not understand "SecondSubformControl is the name of the subform
control that holds the second subform" . Can a control hold a subform?. Also
what do Me and Parent stand for. Thank you for all your help and patence.
 
K

Ken Snell [MVP]

Answers inline...

--

Ken Snell
<MS ACCESS MVP>

Farooq Sheri said:
Thanks. My application is working correctly without running the GetFocus
procedure. I will definitely try out your two suggestions because I may need
these in the future. I am very new to access (this is my first application)
therefore a lot of things are new and for each answer I get I have more
questions. For example from which main form procedure should I run
Call Form_NameOfSubformForm_GotFocus()

You can call the procedure from any procedure in the main form's module.

Also I do not understand "SecondSubformControl is the name of the subform
control that holds the second subform" . Can a control hold a subform?.

A subform is contained in a control called a subform control. This control
is a control on the main form, and its source object is the form that is
serving as the subform. If you open a form in design view, make the Toolbox
visible, and then click on the subform image and then click on the form, a
subform object is put on the form. That object is a control -- a subform
control.

Also
what do Me and Parent stand for.

Me is a shorthand reference to the class in which the code is running. In
this case, it is a shortcut reference to the form that is serving as the
subform. Parent is a property of a subform (and any other control) that
references the object that the control is a child of. So in this case,
Parent refers to the main form that contains the subform control.

You can obtain a book about Access VBA to get more details about these
references and terms. Good luck.
 

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