473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Highlight List Box

1,430 Expert 1GB
Simplified Version:

I Have a table of Entrants with EntantID as the Primary Key, EntrantName and AddressID as a Foreign Key

I Have a table of Addresses with AddressID as the primary Key and Address as text.

I have a list box (LstAddressID) showing all the addresses, so when I add a new Entrant, if the address already exists, I select it from the list box and the AfterUpdate adds the AddressID into the Entrants Table.
No Problem.

If I have to add a new address, I start typing into an unbound field called NewAddress1. Now I am assuming that this really is a new Address, but it may not be, so what I want to happen is the LstAddressID to highlight the first address that partially matches the letters typed into NewAddress1.

I have tried
Expand|Select|Wrap|Line Numbers
  1. Private Sub NewAddress1_Change()
  3.  'start where we are in the list and go forward
  4.     Dim iLength As Integer
  5.     Dim irow As Integer
  6.     iLength = Len(Me.NewAddress1.Text)
  8.     If iLength = 0 Then
  9.         Exit Sub
  10.     End If
  12.     For irow = 0 To Me.LstAddressID.ListCount - 1
  13.         Me.LstAddressID.SetFocus
  14.         Me.LstAddressID.ListIndex = irow
  15.         Me.NewAddress1.SetFocus
  16.         If Left(Me.LstAddressID.Column(1), iLength) = Me.NewAddress1 Then
  17.             Exit Sub
  18.         End If
  19.     Next
  21. End Sub
Me.LstAddressID.ListIndex = irow doesn't work without setting the focus to the listbox, and of course once you move the focus away from the list box, the AfterUpdate fires. Not what is wanted.

Any ideas please

May 8 '17 #1
6 976
32,556 Expert Mod 16PB
Hi Phil.

I'm not sure about this but I believe, with a ComboBox at least so may be similar for non-multi-value ListBoxes, that you can set the .Value property of the control without it having the focus. That's how I normally select an item in a ComboBox programmatically.

If that gives no joy then you may be out of luck. Of course you could always set a flag and allow the AfterUpdate procedure to skip its code when that flag's set. Not sure if that suits but could be a worst case scenario.

Anyway, good luck with your project :-)

May 8 '17 #2
1,107 Expert 1GB
You might try using a DCount() (or DLOOKUP to get the ID) with the same WHERE clause as the ListBox while adding the criteria for LEFT() matching. Then navigate to the ListBox, or set it's .Value only if you get a hit.
May 9 '17 #3
1,430 Expert 1GB
Having slept on it, I think I might replace the list box with a continuous subform, and filter the subform using the OnChange of the letters in the TextBox NewAddress1

I'll let you know results in due course, but your remarks at least prompted me to think outside the box, so as ever, thanks guys.

May 9 '17 #4
32,556 Expert Mod 16PB
Always a pleasure Phil.

Frankly I prefer a rethink than simply following advice. It indicates a greater level of engagement. Good for you.
May 9 '17 #5
1,430 Expert 1GB
Thanks, NeoPa & Ade.

The unbound subform works perfectly.
The OnCurrent of the main form used the AddressID to find the appropriate Address in the subform.

If I start to type a new address in, I apply a filter to the subform, based on the letters typed in so far, so the subform shows the best match. If it is a new address, the subform is blank.


May 11 '17 #6
32,556 Expert Mod 16PB
That's what we aim for. Very happy to see you achieve it on this occasion. Nice work :-)
May 11 '17 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Colin Steadman | last post by:
I have a dropdown list with a couple of dozen entries. I can change the backgroup and text colour. But I cant find the CSS attribute which changes the highlight colour which appears as the mouse...
by: Shyguy | last post by:
When I open my form nothing is selected in the list box. After making a selection it stays highlighted. I have been trying to get it back to the "nothing selected" state, but with no luck. I...
by: Not Me | last post by:
Hey, In our database, we have implemented auditing simply by holding a copy of each row of the specific table at any time that data is updated. This gives us a long list of full records, often...
by: John Morgan | last post by:
I am using a database to populate a drop down list using myDropDownList.DataSource = myCmd.ExecuteReader myDropDownList.DataBind() That works alright and a few lines later in the code I wish...
by: Atara | last post by:
I am trying to convert the following code to VB .Net, I still have some gaps (the lines that are marked with (*)) and also I need an ending condition for the while loop. any help would be...
by: VikasPradhan | last post by:
i am developing C# application in that i have two list views in a form these list views have entries. i want to highlight the entry of list view.. how can i highlight entry of two List views
by: sujathaeeshan | last post by:
Hello all, I want to highlight or select data grid row based on first letter of first column in data grid with keyboard. Just by pressing the key of first letter of the column ,it has to...
by: pavanip | last post by:
Hi, I am having 2 dropdown lists 1st dropdownlist contains A-Z list.2nd dropdown list contains some names like akila,bindu,chinni,....zibra etc. when i select name in 2nd dropdown list, the...
by: rotaryfreak | last post by:
Hello, I am new to C#/ASP.NET so im not quite sure how to go about doing this. I am building a website which allows users to upload documents in .pdf, .html or .txt. I then take the uploaded...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.