I have a simple combobox in Access which serves as a result set holder and contains two columns id and name.
I have developed a simple search feature,
i.e user types in a keyword in a textbox and the combobox returns the results after searching the substring,
Example:
TXT BOX Input: App
Combobox Results:
ID Name
1 Cinnamon Apple
2 Apple Candy Box
42 Carton of Apples
54 iphone App
6 App Store
Now when I go to search the combobox box within the results and I type "i", I expect to select "iphone App" from the drop down but nothing happens because it is searching the first column i.e ID
So how can I search for the names and autocomplete the combobox? or search by second column
Also, It is important for me to show the ID, If I hide the ID column I can search by the Name just fine, since it is the only column in the result set.
Hiding the ID is the simplest way of accomplishing what you want, but I recognize that you said you don't want to hide the ID field.
I think it is possible to do what you want. Basically, on every keypress you will need to reset the RowSource for the combobox to be filtered down to only items that match the users keypress. In my experience, this works best in dropdown menus that you are using for filtering, as opposed to dropdowns used for data entry, especially if you are using a continuous or datasheet form. There are a lot of gotchas and caveats you'll run into when doing this. I can't really recommend attempting this unless you are an experienced VBA programmer. My own implementation uses quite a number of events to make it work including Enter, KeyUp, KeyDown, KeyPress, and AfterUpdate. I also use a timer so that I can accumulate their keypresses and only change the rowsource after some 300ms of no keypresses. I also use ADO with a Disconnected Recordset so that I can filter the recordset without making calls to the database again (in the name of efficiency and "keeping the wire cool").
If you want some code, I did post a very basic version of this early in my development of the idea over at UtterAccess. I think it's probably going to be buggy and it might not work properly with you wanting to show the ID field. That is something that I had to make work properly on one of my projects since I originally posted my code.
http://www.utteraccess.com/forum/Autocomplete-Autosugges-t1986007.html
The Workaround is to show Name and then ID in the Combobox, So when I start typing in the Combobox , it Autocompletes Name by Default instead of ID.
Related
Given I've created an Access Form with a ListBox; property > other > Multi Select = Extended; which permits multiple selections.
User selects multiple items.
Clicks a button that creates a report in "Print Preview"; but this report is based on the query, and the query is based on the values in the form.
This is accomplished by using this in the query when viewing in Access Query Design View (not SQL):
Like ([forms]![padc]![V2])
Where the form name is padc and the value to compare is V2.
Previously, rather than the ListBox that might show 10 options, V2 was just a field with one value. A user would either type a partial value, such as jack*, and the report would pull every instance where this value began with jack; whether that was jack, or jackie, or jacko, or jackson, etc. The LIKE part of this permitted the "fuzzy" logic bringing about varied results. The query would run, and the report would show all the records with anything starting with jack.
My goal, really, is to have a user select one, two or three, or all the available options in this box, and have the report respond correctly.
I believe the ListBox will let me do this, provided I have all the right names in the table that is the source of the options available to choose from.
I set the listbox to "multi-select" to enable multiple selections on the form.
The form is happy. It can let me click/highlight one or several items from the list.
The query is not happy.
For the field V2, neither
Like ([forms]![padc]![V2])
nor
=([forms]![padc]![V2])
Will retrieve records to populate the report; regardless of whether or not just one value in ListBox is selected or multiple values. (Like = fuzzy, and = means exact match.)
Neither work.
Of course, if the query won't perform, then the report won't perform either.
How can I write the correct query in Access, using "Query View = Design View" and or SQL to get this to function properly?
If the answer is "it can't be done without using VBA" then please point me to the VBA solution that a 5-yr old can understand, because I have zero experience using VBA.
Folks have recommended I use VBA; specifically that I should incorporate the "IN() IN function" in some manner; but I don't comprehend this solution at all.
I admit to being ignorant; not stupid; but ignorant.
Ok so I have a super simple database I am using to try to implement things for a more complicated database however I keep hitting walls on what seems like simple things
The database has one table contactsT with the fields ID first_name last_name I have one form with two combo boxes cboFirstName and cboLastName. I have some repeat first names and I only want the combo box to show unique names. I found this absolutely by the numbers tutorial,
https://www.techonthenet.com/access/comboboxes/unique_values2013.php
however it doesn't work which is baffling because it seems very simple. All that happens is I get nothing now showing in the combo box. Don't see an option to attach the database but here is the table
ID first_name last_name
1 Oliver North
2 Oliver Twist
3 Ren Saturn
4 John Smith
5 John Ringo
the Row source is
SELECT DISTINCT contactsT.first_name FROM contactsT
Your assessment is correct, DISTINCT does not work if you create a ComboBox and use the wizard to link it to a specific source.
The easiest way to bypass this is to simply create a ComboBox, hit cancel on the wizard and then type the query in manually into the property sheet.
This should solve your problem.
FYI: This is due to the fact that Access will try and base the ComboBox on the ID field by default, because of that, the fields you are seeing are technically unique, but only based on the the ID column.
Additionally, this can be circumvented in another method, perhaps you would prefer this (although I find it to be more difficult and slightly frustrating):
You can go into the Property Sheet of the ComboBox and change the Column Widths to include only one column, it most likely currently looks something like 0";1". So to fix it, remove the 0, like 1", this is where Access will "hide" the ID field on the ComboBox. If you then manually edit the query to be DISTINCT for the field you are looking for, that should also fix the problem.
I am trying to design a form where the user can search records to filter a report. The user must be able to select many values from a particular field (multivalued field). I understand I can use a list box, but the field has a total of 3,000 records and cycling through is too much. I just want to know what other ways I can let the user insert multiple values?
I have these ideas, but maybe you guys have another better way:
Creating multiple combo boxes and keep them hidden until the user hits an “add” button, but this limits me to the amount of values I can have. If I have 10 hidden combo boxes I can only enter a total of 11 (10 hidden plus the original visible) values.
Is it possible to have a temporary data grid where the user just enters the values.
Then comes the problem of getting this into the SQL Record Source. I am thinking of the SQL IN clause.
Any help or ideas, will be greatly appreciated.
I think that you should create Comboboxes where values from next combo are dynamically populated when value in previous Combo has been changed so that way you can create hierarchy of values to select.
I've done something similar for a few different applications in slightly different ways. Basically, I present the user with a table, allow them to right-click > filter (the same could be accomplished by providing a filter textbox for each corresponding field in the table you want to allow filtering on... in your case it sounds like you only need one). The filter box allows them to use 'and' and 'or' along with the actual text of what they're looking for. Then they click a button that opens the report and fills the report's filter field with whatever filter they had applied.
Of course, this assumes the user is familiar with the data they're filtering, and requires a bit of training, but for me it was a simpler alternative than displaying a list with a bajillion entries in it. Your mileage of course may vary :)
I have an Access database that is used to store basic info in a table such as first and last name. How would I go about adding the functionality to lookup by last name?
Is there a way to type in the last name and then hit like F12 or something like this? Can someone please point me in the right direction or provide me a link?
SELECT tblPatient.LName AS [Last], tblPatient.FName AS [First]
FROM tblPatient
WHERE (((tblPatient.LName)=[Enter Last Name]));
How do I tie this into my form now?
I'd suggest you create a form, with a textbox 'search' at the top, then either a listbox or subform below to display results.
The listbox record source would be:
SELECT tblPatient.LName, tblPatient.FName
FROM tblPatient
WHERE tblPatient.LName LIKE Forms!myForm!search & '*';
You can either add a Search button, which requeries the listbox, or do the requery via the Change event of the search textbox. The later may be slow if you have a large number of records; if that's the case, you could check that at least 3 (?) characters have been entered before calling the requery.
You just need to create a query in which you put =[?] as the "last name" value.
When you open that view, you'll be asked to type in a lookup value for that field.
Not sure if this is what you are trying to archieve, though...
This is probably a bit overkill for what you want to do, but I assume that you want to perform a search by last name. You should be able to glean the information you need from this article:
Build a search criteria form
http://www.everythingaccess.com/tutorials.asp?ID=Build-a-search-criteria-form
You can create queries in Access if the user you're targeting with the searchability has Access themselves.
From the main Access UI (assuming Access 2007), go to the Create tab and then select the "Query Wizard." Here is an article on the subject.
Otherwise you can create a program and connect to the MDB/ACCDB file running the query programmatically.
Seeing you wish to look up a name and populate the form based on the name selected, I suggest you need a combobox. There is even a wizard for doing exactly what you want. To start, you will need a form bound to a table or query, that is a form with a Record Source.
Add a combobox to your form
Select :
Find a record on my form based on the value I select in my combobox
Select the ID (primary key), Last and First name fields.
Access will display an example, suggesting that you hide the Key (id) column. Accept this.
Choose a name and finish.
There are a few other small things that could be done for neatness, but you will end up with a form that find the record you want. In addition, the combo will autocomplete if you type in a few letter.
If this is an mde, which your subsequent post seems to suggest it is, there is little you can do wuth out the original file. However, you could try opening the database while keeping the shift key held down and see if that allows you to edit. If you cannot get the original and the shift does not work, you could try rescuing the data, if it, too, is stored in this file.
I am new to Access and i am in the process of creating a database for some of our users. I have designed a form where the user name, first and last name etc are inputted.
Some of these users work for more than one department which means I need some type of listbox control that allows them to select more than one department when they enter their contact info.
In VB Studios 2005, this control is called a CHECKED LISTBOX. I have looked everywhere in access but cant seem to find it or anything closely similar.
The option of a listbox or combobox is not feasible here as these only allow the user to select one option only when inputting their details. Any help with this is much appreciated.
Use an ordinary list box with the "Multi Select" property set to "Simple".
The user can then click multiple list items, all of which stay selected until they un-select them again.
You may wish to consider a subform, as this will save you the trouble of updating a table with the data from a list box. A subform can use a department-person junction table with person id as the linked child field and master field. A combobox bound to department id will allow the user to select departments.
If you are really set on having checkboxes, Stephen Lebans has a sample database that uses the built-in Access listbox with checkboxes (from one of the Access wizards).
There is another choice:
If you are using Access 2007, you can declare your field as a lookup field accepting multiple values.
When you bind the list box to that field, you will get checkboxes.
It's easy to use them.
You'll also find more information is available from the MS Office website.
However, note:
This is only possible in the new Access 2007 database format and you will not be able to save your database to the older MDB format.
Multiple value fields are not compatible with most other databases, meaning that if you decide one day to upsize to SQL Server, you'll have to redesign your tables to use a junction table as Remou mentioned.
These multi-value fields are difficult to use from VBA: the value they return is in fact another recordset that you must iterate through to get all the values.
Having said that, if you just want something simple and you're not planning on manipulating the database from code, then it can be a practical option, albeit not a very compatible or future-proof one.
I'm not using them, but I think others should be able make their own decision knowing what is available to them.