Solved FAYT Listbox Tab (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
Ok... this is in reference to a previous post but that problem was solved so I'm starting a new one.
I have a MAJP listbox popup form. On open the focus is set to a txtbox for typing in a search text. Before anything is typed in, you can tab to the list box. After anything is typed in you cannot tab out of the txtbox. The only way of selecting an item from the list box is by mousing it.

I notice on the listbox demo in the FAYT v.17 that tabbing out of the selection box clears the box and the listbox loses its filter and fills again. This doesn't seem intuitive. I want the list to stay filtered while I tab in to make a selection.

Such a small thing but annoying as all get out.
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:32
Joined
Sep 21, 2011
Messages
14,305
From post #9 of your other thread, posted by @MajP

I have it set up so once you make a selection the list unfilters. If you want to tab in then use the arrows I would have to add some features. But not sure of the logic then to determine when to unfilter. It could be set up to unfilter only on hitting return.
 

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
Exactly. To limit it to the selection you want, you may need to type a looong text to get to the right selection.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
Not at my computer but thinking to unfilter on the lists on exit event and not the afterupdate.
I will post update, seems logical.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
@ClaraBarton Can you demo this version of the class. I think this may do what you want, but not sure if I broke anything.

Now looking at this, there is a lot more functionality then I thought.
1. You can pick as many fields to search and modify that on the fly
2. You can change the search from searching from the beginning to searching anywhere and do that on the fly
3. You can sort dynamically
 

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
YES! One little problem... when I tab to the list box (which I can do now as the txtbox doesn't clear) it wants to select the first highlighted entry. The down arrow selects instead of moving down... Can I (you?) fix this? I'm not asking too much... am I?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
Thanks these are good suggestions. See if this version is better.

In the initialize you have to also pass an additional parameter. You will have to modify your current call to initialize.
UnselectOnFilter: yes no

New behavior
1. The lisbox does not select a value when filtering until there is only one item left
2. If you tab into the list then nothing gets selected until you use the arrow keys, hit return, use the mouse, or actively select
3. If you then leave the listbox and start refiltering then if the UnselectOnFilter is set to true the value of the listbox is unselected.

See new behavior.

I imagine there are as may cases where you want to select a value then start filtering Without unselecting the current value. So I made this a parameter to pick what behavior you want.
 

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
This is what I want but... You don't do anything with your picked value so I don't know how to implement that. I want to make a choice and close the form. Both of the these subs close the form on the first choice:
Code:
faytList.Initialize Me.lstChild, Me.txtSearch, ftlb_AnywhereInString, True, "Child"

'Private Sub lstChild_AfterUpdate()
'
'    TempVars("ChildID").Value = Me!lstChild.Value
'   'Terminate the class by setting it to nothing
'' Set faytList = Nothing
'DoCmd.Close acForm, Me.Name
'
'End Sub

Private Sub lstChild_Click()
    TempVars("ChildID").Value = Me!lstChild.Value
    DoCmd.Close acForm, Me.Name
End Sub

Turns out click and double click are only for mousing and then I'm back to the start.
Perhaps I need to add a close button? Hmm... I suppose that would work.
 
Last edited:

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
The Close button works but seems a little clumsy. Hitting AltC unfilters the list so I need to AltC twice. It works but you don't realize it works when you're doing it.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
For sure you cannot close on the after update. If you use the arrow keys then it fires the after update and that is an Access event. No way to bypass.

Use the key down and key press. I used both to reduce the if checks. One for everything but arrows and one to handle the enter key.

Code:
Private Sub lstSearch_KeyPress(KeyAscii As Integer)
  'Cannot use the tab because the tab would close out on enter
  If KeyAscii <> 9 Then closeform
End Sub
Private Sub lstSearch_KeyDown(KeyCode As Integer, Shift As Integer)
 'capture return not handled above
  If KeyCode = 13 Then closeform
End Sub
Public Sub closeform()
  DoCmd.Close acForm, Me.Name
End Sub

Also to the original problem. I would update the terminate event. I needed to check that the recordset was not nothing before trying to close it. Might have been the issue.

Code:
Private Sub Class_Terminate()
    If Not mRsOriginalList Is Nothing Then mRsOriginalList.Close
    Set mRsOriginalList = Nothing
    Set mForm = Nothing
    Set mListbox = Nothing
End Sub
 

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
PERFECT!!!! I feel very spoiled but very... whatever, it's the greatest! It works exactly as I envisioned.
Code:
Private Sub lstChild_KeyPress(KeyAscii As Integer)
  'Cannot use the tab because the tab would close out on enter
  If KeyAscii <> 9 Then
    TempVars("ChildID").Value = Me!lstChild.Value
    closeform
  End If
End Sub
Private Sub lstChild_KeyDown(KeyCode As Integer, Shift As Integer)
'capture return not handled above
  If KeyCode = 13 Then
    TempVars("ChildID").Value = Me!lstChild.Value
    closeform
  End If
End Sub
Thank you so much!
 
Last edited:

ClaraBarton

Registered User.
Local time
Today, 04:32
Joined
Oct 14, 2019
Messages
463
I'm a bit of a pain, I know... but if I need to add a new child to the list, I have a button that takes me to another dialog form. After adding a new record I want the (still open) list to grab the new record. I use the following:
Code:
Forms!popPickChild.faytList.Requery
but it doesn't. Am I doing this wrong?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
No problem with asking for the help. You have helped me to make this much better and discovered some actual bugs so I appreciate that.
 

KitaYama

Well-known member
Local time
Today, 20:32
Joined
Jan 6, 2022
Messages
1,541
to make this much better
I stayed away and hoped the OP mention it.

For the sake of perfectness you may want to know, in Find As You Type Listbox form, Clicking headers to sort the listbox in some cases causes error. I had no time to check, but I assume it's when the rowsource of the listbox contains a calculated field such as
CStr(Nz([QuantityPerUnit],"")) AS Quantity
Or
CStr(Date()+[productID]) AS DateField
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:32
Joined
May 21, 2018
Messages
8,529
Thanks. The problem was the code in the form (not the class) was storing the field name in the Tag property of the textbox and I forgot to rename the tags correctly. I posted an update.
Code:
Public Function SortList()
  Dim ctrl As Access.Control
  Set ctrl = Me.ActiveControl
  'MsgBox ctrl.Tag
  faytLst.SortList (ctrl.Tag)
  If Right(ctrl.Tag, 4) = "DESC" Then
    ctrl.Tag = Trim(Left(ctrl.Tag, Len(ctrl.Tag) - 4))
  Else
    ctrl.Tag = Trim(ctrl.Tag) & " DESC"
  End If
End Function
 

Users who are viewing this thread

Top Bottom