Overriding an OnExit event

D

Dennis

I have a form that looks like this:

Actn Model Description
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]

<* SUBMIT *> <* Close Form *>

(ACTN is: A)dd, C)hange or D)elete)

The OnExit event for Model and/or description sets focus to the next Action
column down. If I click SUBMIT with the cursor in the Model or Description
fields, the OnExit event does exactly what it should (as described above).
However, if I click the buttons, I DO NOT want to go to the next field. I
want to perform the OnClick event for the button(s) instead.

How can I make that happen?

Thanks!!
 
M

Marshall Barton

Dennis said:
I have a form that looks like this:

Actn Model Description
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]

<* SUBMIT *> <* Close Form *>

(ACTN is: A)dd, C)hange or D)elete)

The OnExit event for Model and/or description sets focus to the next Action
column down. If I click SUBMIT with the cursor in the Model or Description
fields, the OnExit event does exactly what it should (as described above).
However, if I click the buttons, I DO NOT want to go to the next field. I
want to perform the OnClick event for the button(s) instead.


You will have to use something other than a command button
for Submit. There are two choices that come to mind that
will not move the focus. One is a custom toolbar button,
but that can not be on the form. The other is a label
control, but you can not tab to a label, only click on it.

Alternatively, I think you should be able to work out a way
for the control's Exit event to save something that
indicates the control that is giving up the focus and then
the button can (re)set the focus back to the one that had
it.
 
D

Dirk Goldgar

Dennis said:
I have a form that looks like this:

Actn Model Description
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]

<* SUBMIT *> <* Close Form *>

(ACTN is: A)dd, C)hange or D)elete)

The OnExit event for Model and/or description sets focus to the next
Action column down. If I click SUBMIT with the cursor in the Model or
Description fields, the OnExit event does exactly what it should (as
described above). However, if I click the buttons, I DO NOT want to
go to the next field. I want to perform the OnClick event for the
button(s) instead.

How can I make that happen?

Thanks!!

One alternative would be to *not* use the Exit event of those controls
to move the focus. Instead, you might add an infinitesimal text box
(width 0, height 0) or transparent command button and put it next in the
tab order, and use the GotFocus event of *that* control to move the
focus to the next Action. That way, tabbing or pressing Enter to exit
the Model (or Description, depending on where you put this) would result
in the focus being set to the next Action, but clicking the SUBMIT
button would not let the focus go to that special control and so the
focus would arrive, and remain, on the button.
 
D

Dennis

I don't want to return the focus to the preceding field after the SUBMIT
button is clicked. I'm going to do "other things" at that point, and upon
repaint of the form, the foucs will be back on the first ACTN field.

How can I use a LABEL to click on? I've never heard of doing that, and the
EVENT tab for a label is blank.

One more thing: If the EXIT event is triggered when I click SUBMIT, can I
query for that OnClick event inside the OnExit event of the preceding
control? How might I do that?

Thanks!
 
D

Dennis

I like that approach too.Simple and elegant. The only thing I dislike is all
the extra invisible controls on the form Might there be a way for ONE
invisble button to direct the focus to ANY of the other controls, depending
on where the focus was received from? How might I do that?

Thanks!

Dirk Goldgar said:
Dennis said:
I have a form that looks like this:

Actn Model Description
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]

<* SUBMIT *> <* Close Form *>

(ACTN is: A)dd, C)hange or D)elete)

The OnExit event for Model and/or description sets focus to the next
Action column down. If I click SUBMIT with the cursor in the Model or
Description fields, the OnExit event does exactly what it should (as
described above). However, if I click the buttons, I DO NOT want to
go to the next field. I want to perform the OnClick event for the
button(s) instead.

How can I make that happen?

Thanks!!

One alternative would be to *not* use the Exit event of those controls
to move the focus. Instead, you might add an infinitesimal text box
(width 0, height 0) or transparent command button and put it next in the
tab order, and use the GotFocus event of *that* control to move the
focus to the next Action. That way, tabbing or pressing Enter to exit
the Model (or Description, depending on where you put this) would result
in the focus being set to the next Action, but clicking the SUBMIT
button would not let the focus go to that special control and so the
focus would arrive, and remain, on the button.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Dennis said:
I like that approach too.Simple and elegant. The only thing I dislike
is all the extra invisible controls on the form Might there be a way
for ONE invisble button to direct the focus to ANY of the other
controls, depending on where the focus was received from? How might I
do that?

I'm not sure I have a good picture of your form. Am I right in thinking
this is not just a continuous form, but rather has a simulated control
array? If so, I think you're not going to be able to have just one
focus-transferring control, because you need to rely on the tab order to
have the focus move automatically from the previous control into that
control -- and there's only one tab order. Maybe your form would be
better redesigned as a continuous form.

If there's some way to solve that problem with the tab order, you can
know what control previously had the focus by interrogating
Screen.PreviousControl.
 
D

Dennis

Yes, you are correct in your design assessment of this form.

As to your statement: "I think you're not going to be able to have just one
focus-transferring control, because you need to rely on the tab order to
have the focus move automatically from the previous control into that
control -- and there's only one tab order", I have been able to alter the
tab-order at runtime, by querying the contents of the ACTN fields.

For example, the NORMAL tab-progression is vertically down the ACTN fields.
However, if you place a character into one of them, the form then tabs ACROSS
to the associated MODEL and DESCRIPTION fields. Upon exit from the associated
DESCRIPTION field, focus is transferred to the NEXT ACTN field down the
screen. That's where the problem lies: when the user types something in the
DESCRIPTION field, then clicks SUBMIT, the affected DESCRIPTION field is
exited. So, focus is transferred directly to the next lower ACTN field.

While fine during data-entry, it's bad for when SUBMIT is clicked on. My
initial post on this issue was to try and find a "clean"
(programatically-speaking) method of overriding the ".SetFocus" when SUBMIT
is clicked. You see, if I can check (in the code for OnExit for that field)
whether or not the SUBMIT button has been clicked, I can place additional
code in the OnExit section to CALL the SUBMIT sub (without having to transfer
actual focus to the button).

See what I mean?

Thanks!
 
D

Dirk Goldgar

Dennis said:
Yes, you are correct in your design assessment of this form.

As to your statement: "I think you're not going to be able to have
just one focus-transferring control, because you need to rely on the
tab order to have the focus move automatically from the previous
control into that control -- and there's only one tab order", I have
been able to alter the tab-order at runtime, by querying the contents
of the ACTN fields.

Have you actually changed the TabIndex properties of the various fields,
or have you just put in code to set the focus to a particular control?
Maybe you can do something where you actually manipulate the controls'
TabIndex properties, but it would be a bit hairy, since changing one
control's TabIndex also modifies the TabIndex properties of other
controls.
For example, the NORMAL tab-progression is vertically down the ACTN
fields. However, if you place a character into one of them, the form
then tabs ACROSS to the associated MODEL and DESCRIPTION fields. Upon
exit from the associated DESCRIPTION field, focus is transferred to
the NEXT ACTN field down the screen. That's where the problem lies:
when the user types something in the DESCRIPTION field, then clicks
SUBMIT, the affected DESCRIPTION field is exited. So, focus is
transferred directly to the next lower ACTN field.

While fine during data-entry, it's bad for when SUBMIT is clicked on.

Yes, I understand all this.
My initial post on this issue was to try and find a "clean"
(programatically-speaking) method of overriding the ".SetFocus" when
SUBMIT is clicked. You see, if I can check (in the code for OnExit
for that field) whether or not the SUBMIT button has been clicked, I
can place additional code in the OnExit section to CALL the SUBMIT
sub (without having to transfer actual focus to the button).

See what I mean?

Unfortunately, there's no "Screen.NextControl" object to tell you which
control is *about* to receive the focus. Using the approach I initially
outlined, I don't see any alternative but to create multiple
focus-transferring controls, one for each row of controls. Note that
you don't actually have to write a separate event procedure for each of
them. You can call a common function directly from the GotFocus event
property; e.g.,

=SendFocusToNextAction()

In that function, you could interrogate Me.ActiveControl to figure out
which Action control to send the focus to.
 
D

Dennis

THANK YOU! That worked. Example:

Dim ctlCC As Control
Set ctlCC = Me.ActiveControl

If ctlCC.Name = "frmPRTR_submit" Then
Call frmPRTR_submit_Click
Exit Sub
End If

This code is placed in the OnExit event for the text entry field. You sir
are a STAR!!

Dennis
 
M

Marshall Barton

Dennis said:
I don't want to return the focus to the preceding field after the SUBMIT
button is clicked. I'm going to do "other things" at that point, and upon
repaint of the form, the foucs will be back on the first ACTN field.

How can I use a LABEL to click on? I've never heard of doing that, and the
EVENT tab for a label is blank.

One more thing: If the EXIT event is triggered when I click SUBMIT, can I
query for that OnClick event inside the OnExit event of the preceding
control? How might I do that?


Forget that I ever said anything about this. I obviously
misunderstood your question and I see that you have found a
way to use Dirk's idea, so it's all moot anyway.

FYI - An **unattached** label control does have several
mouse related events, including Click.
 

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