I have searched and not found an answer to my question so I am posting.
I have a table named FieldData with a lookup field that gets data from another table TrainerInfo that full names in a single field (John Q. Public, Sr.) and it works great.
What I would like to know is when start to type the name "John", can the dropdown list filter names only with John in the field. Also, is there a way (similiar to searching windows explorer) where as I type the field is reduced to only matches of what I have typed no matter where the letter string. As an example typing Pub would narrow the list to John Q. Public, Al's Pub, Public Morals, etc.
The list has over a thousand records so this would make data entry more efficient when typing say John Smith and scrolling through hundres of names to get to John Jones, as well as if I only have an initial say J. Brown I can type Brown and find John Brown.
I know this happens in web pages and windows so I would like to know how to implement if possible.
Thanks
11 1914
I have tried to implement this and it does not appear to be working. I will attach the code from the query that the combo box uses. it has a filter built in already as trainers data is track specific therefore their name may appear multiple times in the table. - SELECT TrainerData.ID, TrainerData.Trainer, TrainerData.Track
-
FROM TrainerData
-
WHERE (((TrainerData.Track)=[Forms]![RaceEntryForm]![Track]));
-
jforbes 1,107
Recognized Expert Top Contributor
You'll have to merge the Where Clause of the TrainerData.Track with what is typed in by the User... Something like this: -
Option Compare Database
-
Option Explicit
-
-
Private bLookupKeyPress As Boolean
-
-
Private Sub cboLookup_Change()
-
Dim sSQL As String
-
Dim sNewLookup As String
-
-
If Not bLookupKeyPress Then
-
sNewLookup = Nz(Me.cboLookup.Text, "")
-
sSQL = sSQL & "SELECT TrainerData.ID, TrainerData.Trainer, TrainerData.Track " -
sSQL = sSQL & " FROM TrainerData " -
sSQL = sSQL & " WHERE TrainerData.Track=[Forms]![RaceEntryForm]![Track] " -
If Len(sNewLookup) <> 0 Then -
sSQL = sSQL & " AND TrainerData.Trainer LIKE '*" & sNewLookup & "*'" -
End If
-
Me.cboLookup.RowSource = sSQL
-
Me.cboLookup.Dropdown
-
End If
-
bLookupKeyPress = False
-
End Sub
-
-
Private Sub cboLookup_KeyDown(KeyCode As Integer, Shift As Integer)
-
Select Case KeyCode
-
Case vbKeyDown, vbKeyUp
-
bLookupKeyPress = True
-
Case Else
-
bLookupKeyPress = False
-
End Select
-
End Sub
-
-
Private Sub cboLookup_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
bLookupKeyPress = True
-
End Sub
-
At anytime while you are getting this to work, you can post your code and we can help you out.
May be simple but just to confirm. Is this going in the on change or AfterUpdate property. Reading post not sure
jforbes 1,107
Recognized Expert Top Contributor
cboLookup was the name of the Control in the example I played around with. You'll probably need to update all the occurances of cboLookup with the Name of your Control.
To answer your question, it's the OnChange Event: - Private Sub cboLookup_
Change ()
For a little more explanation, there are three events involved: - OnChange - Where the ComboBox Rowsource is updated based on what has been entered so far.
- OnKeyDown - To flag the Input as User input and not something changed by Access, like navigating to a different row.
- OnMouseDown - To show the Dropdown list when the user clicks in the Combobox.
- Private bLookupKeyPress As Boolean
will need to be put at the top of the Form's code. It's the Flag that is set whenever a user performs some input in the ComboBox.
Worked like a champ. Thanks for the help!
Stuck again! The search works great, however I now have a problem where when I go to the next record, the last chosen item is in the field instead of going blank.
jforbes 1,107
Recognized Expert Top Contributor
I think I see what you are talking about. The Dropdown would still be filtered to what was used on the previous record. It would need to be reset as the User navigates through the records. I played around with it a bit and came up something like this: - Private Sub Form_Current()
-
Dim sSQL As String
-
sSQL = sSQL & "SELECT TrainerData.ID, TrainerData.Trainer, TrainerData.Track "
-
sSQL = sSQL & " FROM TrainerData "
-
sSQL = sSQL & " WHERE TrainerData.Track=[Forms]![RaceEntryForm]![Track] "
-
If Me.cboLookup.RowSource <> sSQL Then Me.cboLookup.RowSource = sSQL
-
End Sub
This will reset the RowSource of the ComboBox whenever the User navigates to a different record. I put the Test in there so that the RowSource is only Reset if it needs to be. It should run better that way.
To make this a bit cleaner, you may want to relocate this into it's own function and call the function from the OnCurrent event.
Placed it in OnCurrent and get Compile Error. Method of Data Member not found. TrainerLookup is my control box name - Option Compare Database
-
-
Private Sub Form_Current()
-
-
Dim sSQL As String
-
sSQL = sSQL & "SELECT TrainerData.ID, TrainerData.Trainer, TrainerData.Track "
-
sSQL = sSQL & " FROM TrainerData "
-
sSQL = sSQL & " WHERE TrainerData.Track=[Forms]![RaceEntryForm]![Track] "
-
If Me.TrainerLookup.RowSource <> sSQL Then Me.TrainerLookup.RowSource = sSQL
-
End Sub
jforbes 1,107
Recognized Expert Top Contributor
Hmmm, looks like it's having trouble resolving something. It could be the where clause. Might want try commenting out line 8 just to rule it out. You may also want to check line 6 and 7 to make sure they match your Column names and Table name.
The idea behind this it to reset the RowSource so that it is wide open. So you would want to set it to whatever you set it to for the OnCurrent Event, minus additional filtering from what the user typed in. The code I posted is just a guess based on what you provided.
If you are still stuck after looking at it again, maybe post all the code you have and we can try to get it working.
... I'm about to go on a 5 day vacation, so if I can't help you, hopefully someone else can. I hope to check in from time to time, but It might be difficult while canoeing. =)
I just realized this is on a subform and that has no OnCurrent. The code was placed in the RaceEntryForm which has the child FieldData Subform. All the tables and fields are correct
Sign in to post your reply or Sign up for a free account.
Similar topics
by: William Wisnieski |
last post by:
Hello Everyone,
I have a main form with a datasheet subform that I use to query by form.
After the user selects two criteria on the main form and clicks the
cmdShowResults button on the main...
|
by: diskoduro |
last post by:
Hi!
I'm trying to get help to an unexpected problem that has appeared
while I was writing a new application.
I want to opeon a report of product sales by filtering previously from
a listbox in a...
|
by: Colleyville Alan |
last post by:
I have a listbox that is populated with info and when the user selects
categories of things from the list, it brings up detailed items from which
to choose. I want to be able to put a filter on...
|
by: Alpha |
last post by:
I have a listbox with datasource from a dataview. When a user selects a
different item in a combobox then I need to refresh the listbox to the
appropriate listing based on that combobox's selected...
|
by: hackerslacker |
last post by:
I have an ordering form that use two combo boxes to filter down the
records of a Products table. This worked fine with the after_Update of
the first filtering the records and creating the...
|
by: Prochot |
last post by:
I'm trying to design a database to track projects and the associates
assigned to them. I have almost no experience with this. I have three
tables:
-Projects
-Associates
-Assignments
where...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a ListBox on my Visual Studio C# form with several entries (14,000).
I have to put a search field on the form. As text is entered into the search
field, I want the ListBox to remove...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a ListBox on my form with lots of data in it (14000 entries).
I have to put a search field on the form. As text is entered into the search
field, I want the ListBox to remove entries...
|
by: lhsiber |
last post by:
I am new to access and am having a problem with filtering. Here is a little bit of my setup: I have a main form that has a listbox so that users can choose one or many groups in which to display...
|
by: Jeroen3131 |
last post by:
I have a Form with four comboboxes (cboSelectDepartment, cboSelectOperation, cboSelectModel and cboSelectVariant), a Listbox (selectionList) and a Button (cmdSelectStep).
The Listbox displays a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |