search listbox problem (1 Viewer)

Nile80

New member
Local time
Today, 10:34
Joined
Jan 21, 2020
Messages
3
Hi everyone. My problem is when I search listbox from textbox by number everything is ok. But when I search by name problem is when I need to type SPACE (bethween name-surname) cursor dont make space. when I tipe ? for example (as a subtitution for SPACE) it go to surname.
 

Attachments

  • example.accdb
    432 KB · Views: 61

isladogs

MVP / VIP
Local time
Today, 17:34
Joined
Jan 14, 2017
Messages
18,186
The Change event fires after each key stroke causing unwanted flickering as well as this issue
Use the AfterUpdate event instead which will only fire after you press Enter

The code can be simplified to:

Code:
Private Sub pret2_AfterUpdate()
   Me.Popis48.Requery
End Sub

You could scrap the change event on the other tab and just use this:
Code:
Private Sub pret1_AfterUpdate()
    Me.Popis38.Requery
    Me.Tekst40 = Me.Popis38.Column(2)
    Me.Tekst44 = Me.Popis38.Column(3)
    Me.Tekst46 = Me.Popis38.Column(4)
End Sub
 

June7

AWF VIP
Local time
Today, 09:34
Joined
Mar 9, 2014
Messages
5,423
Problem with this approach is that Access drops trailing spaces from data. So when placing cursor with SelStart the trailing space is dropped each time. I have never used Change event and I really don't have a solution. I would just use a combobox with AutoExpand.

I wonder if Allen Browne deals with this in his procedure http://allenbrowne.com/AppFindAsUType2.html
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:34
Joined
May 21, 2018
Messages
8,463
I do all of this in class modules so I never have to constantly rewrite code and come up with these complicated design. Here is all the code to make it work.

Code:
Private fayt_Lst As FindAsYouTypeListBox
Private Sub Form_Load()
  Set fayt_Lst = New FindAsYouTypeListBox
  fayt_Lst.Initialize Me.lstKonto, Me.txtSearch
End Sub

Also I only need one box to search by number or name.
 

Attachments

  • MajP_example.accdb
    904 KB · Views: 64

Nile80

New member
Local time
Today, 10:34
Joined
Jan 21, 2020
Messages
3
Well done. I'm begginer in access and modules are new for me, but I hope I will understand it. Is this module work only with 2 search or more (ID, name, phonenumber etc)? Thanks all.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:34
Joined
May 21, 2018
Messages
8,463
t. Is this module work only with 2 search or more (ID, name, phonenumber etc)? Thanks all.

It will work with every field that is text in the recordsource. If the recordsource is a query convert number and date fields if you want to search them. See listbox example in the FAYT database for a much larger listbox.
https://www.access-programmers.co.uk/forums/showpost.php?p=1663332&postcount=60

To convert a string to text in a query you would in design view do something like

strDateField:cstr([YourDateField]) strNumberField:cstr([YourNumberField])

If you want to use class modules you do not need to understand how they work, only how to use them. The class module is a "black box", you only need to understand the inputs and outputs. This module has a lot of features and configurations, so if you want to try to understand how it works, that may take some time. I use class modules so I can build the detailed code once and use it every time without any modification.

However, I believe there are some corruption issues with your database. I tried to fix your form using your approach and could not so I provided my solution. Some simple code would not compile. You may want to import into a new database or recreate your form. Worst case you will need to do a decompile. The issue is you call Refresh, which I would think is not even required because the requery should be sufficient. Refresh removes the space when saving. However, when I remove Refresh the filter is not shown. That is another reason I think there is some corruption on the form.

You may also want to look at the Allen Browne link. This is a cleaner approach than what you were trying if you prefer not to use Custom Classes.
 

Users who are viewing this thread

Top Bottom