Keeping track of which listbox has focus: Best approach question

P

paul.schrum

Access 2007 working in compatibility mode with a 2003 database.

I have three list boxes on a tab page. I also have buttons that
operate based on which list box has focus. So my approach has been to
keep track of which list box has focus by having the following kind of
code in the On Got Focus function of each list box:

Private Sub lbx_suspendedIndefinitely_manageMyTasks_GotFocus()
If Not (IsNull(Me.lbx_suspendedIndefinitely_manageMyTasks)) Then
Set suspendedListBoxWithFocus =
Me.lbx_suspendedIndefinitely_manageMyTasks
End If
End Sub

in which suspendedListBoxWithFocus is global to the form module.

Ultimately the problem I am running in to is that
suspendedListBoxWithFocus has a value of Nothing, so the Set code line
never does anything. I tried putting

suspendedListBoxWithFocus = New ListBox
Set suspendedListBoxWithFocus = Null

in the form's On Open subroutine, but this is also not working.

I think my whole approach must be hopeless. Can anyone suggest a
better approach to finding out which list box had focus just before
the user selected a command button?

- Paul
Schrum
 
A

Arvin Meyer [MVP]

Why don't you try to enable/disable the command button(s) as each listbox
gains/loses focus?
 
J

Jeff Boyce

Paul

I'm with Arvin ... if you have a command button that is supposed to be
"live" if listbox #2 is (or just was) the active control, have activity in
listbox #2 enable command button #2 (and disable cbs #1 & #3).

Or, if you have command buttons not tightly coupled to the listboxes (e.g.,
one command button, total, doing something different depending on which
listbox was exited), another approach might be to add a (hidden) control on
the form that will hold the "number" of the listbox just exited. Then your
(single) command button just reads that (hidden) control to decide what to
do...

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
M

Marshall Barton

Access 2007 working in compatibility mode with a 2003 database.

I have three list boxes on a tab page. I also have buttons that
operate based on which list box has focus. So my approach has been to
keep track of which list box has focus by having the following kind of
code in the On Got Focus function of each list box:

Private Sub lbx_suspendedIndefinitely_manageMyTasks_GotFocus()
If Not (IsNull(Me.lbx_suspendedIndefinitely_manageMyTasks)) Then
Set suspendedListBoxWithFocus =
Me.lbx_suspendedIndefinitely_manageMyTasks
End If
End Sub

in which suspendedListBoxWithFocus is global to the form module.

Ultimately the problem I am running in to is that
suspendedListBoxWithFocus has a value of Nothing, so the Set code line
never does anything. I tried putting

suspendedListBoxWithFocus = New ListBox
Set suspendedListBoxWithFocus = Null

in the form's On Open subroutine, but this is also not working.

I think my whole approach must be hopeless. Can anyone suggest a
better approach to finding out which list box had focus just before
the user selected a command button?

Disabling the buttons is a good idea, but without more
information, I don't where you would do it.

Your current approach might be made to work, but like the
enable/disable, I don't know enough to see where you would
invalidate whatever suspendedListBoxWithFocus is set to. If
you have that figured out or if it's not an issue, then you
should at least fix the syntax of what you tried.

At the top of the module
Private suspendedListBoxWithFocus As ListBox

In each list box's GotFocus
Set suspendedListBoxWithFocus _
= lbx_suspendedIndefinitely_manageMyTasks

There is no need to do anything in the form's Open event,
because lbx_suspendedIndefinitely_manageMyTasks will be
Nothing until one of the list boxes gets the focus. The
buttons' code must check for nothing as well as whatever you
are checking to figure out which list box was the last one
with the focus.

If you want to invalidate the setting for the last list box,
then use:
Set suspendedListBoxWithFocus = Nothing

Note: there is nothing in this discussion to indidicate if
anything was selected in a list box, just that it got the
focus.

You should put more thought into this whole idea to see how
well your UI design will hold up when real **unpredictable**
users get their hands on it.
 
P

paul.schrum

Thanks to everyone for your responses. The suggestion to have a
hidden text field and work with that is what I chose. It seems to be
working well.

- Paul

Access 2007 working in compatibility mode with a 2003 database.
I have three list boxes on a tab page.  I also have buttons that
operate based on which list box has focus.  So my approach has been to
keep track of which list box has focus by having the following kind of
code in the On Got Focus function of each list box:
Private Sub lbx_suspendedIndefinitely_manageMyTasks_GotFocus()
   If Not (IsNull(Me.lbx_suspendedIndefinitely_manageMyTasks)) Then
       Set suspendedListBoxWithFocus =
Me.lbx_suspendedIndefinitely_manageMyTasks
   End If
End Sub
in which suspendedListBoxWithFocus is global to the form module.
Ultimately the problem I am running in to is that
suspendedListBoxWithFocus has a value of Nothing, so the Set code line
never does anything.  I tried putting
   suspendedListBoxWithFocus = New ListBox
   Set suspendedListBoxWithFocus = Null
in the form's On Open subroutine, but this is also not working.
I think my whole approach must be hopeless.  Can anyone suggest a
better approach to finding out which list box had focus just before
the user selected a command button?

Disabling the buttons is a good idea, but without more
information, I don't where you would do it.

Your current approach might be made to work, but like the
enable/disable, I don't know enough to see where you would
invalidate whatever suspendedListBoxWithFocus is set to.  If
you have that figured out or if it's not an issue, then you
should at least fix the syntax of what you tried.

At the top of the module
        Private suspendedListBoxWithFocus As ListBox

In each list box's GotFocus
        Set suspendedListBoxWithFocus _
                                = lbx_suspendedIndefinitely_manageMyTasks

There is no need to do anything in the form's Open event,
because lbx_suspendedIndefinitely_manageMyTasks will be
Nothing until one of the list boxes gets the focus.  The
buttons' code must check for nothing as well as whatever you
are checking to figure out which list box was the last one
with the focus.

If you want to invalidate the setting for the last list box,
then use:
        Set suspendedListBoxWithFocus = Nothing

Note: there is nothing in this discussion to indidicate if
anything was selected in a list box, just that it got the
focus.

You should put more thought into this whole idea to see how
well your UI design will hold up when real **unpredictable**
users get their hands on it.

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -
 

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

Similar Threads

Test which field has focus 4
List Box Focus 4
lost focus...? 3
Continuous form set focus 5
On Got Focus 1
Text box focus without font white on black 2
listbox and set focus 1
Lost Focus Woes 7

Top