I have created a form which allows users to search for data within the database via a form.
The database is restricted and the users are only able to navigate via buttons and forms.
At present, I have developed a form and a query which takes the criteria from a field within the form and then runs the query.
This is the code I use within the query to take the data from the form field:
[Forms]![Query].[refCriteria]
This code is featured under the "Criteria" section of the query design under the Ref field.
However, the query won't work when there is more than one criteria. I have tried entering the following code under the CCG field:
[Forms]![Query].[ccgCriteria]
I notice that when there are two or more instances of the above code within the same query, fails to produce any results.
Further to this, it prevents my users from querying multiple criteria which is certainly a feature that I require.
Is there a way to have any or all of the criteria potentially run via the same query? The only way I can think of getting this to work would be to create numerous queries, all of which would accept a different search criteria, but this is not a practical method.
Query will produce results if you enter both search criteria and you have rows with both fields equal search criteria. If you need to be able to search by just one criteria, leaving some of other search fields empty, use for each column criteria like this:
WHERE
[ref]=[Forms]![Query].[refCriteria] or Nz([Forms]![Query].[refCriteria],"")="" AND
[cgc]=[Forms]![Query].[ccgCriteria] or Nz([Forms]![Query].[ccgCriteria],"")=""
I'd recommend to type the criteria in SQL mode, in graphic mode Access will produce constructions much harder to understand, especially if you have more than 2 search fields.
Related
I have a query in MS Access that pretty much has every data I need for different reports. I know how to filter the query from a combo box in a form, however, I can't do it from multiple forms. Let's say for one occasion I want to filter the query from one form but for another purpose, I want to filter the same query in a different field from another form. When I try it there is a window that pops up asking for the criteria in the other field. Bear me with my English is not my first language.
Respectfully
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.
I have a query which joins a few tables. The query asks for a parameter when it is run. Then it displays a few columns/fields from its results, the other fields (like, the entered parameter and other fields that are common to all rows) are hidden. I'm trying to create my first Access report based on this query and I'd like to use some of these hidden fields as a record source for text-boxes/labels but I've been unable to do so. Those fields don't appear in the list of possible record sources.
I've tried the Add Existing Fields button and selecting the field I want from Fields in related tables but when the bound textbox shows up in the report with an error like Invalid Control Property. No Such Field in the Field List which I think means the fields are still invisible to the report. Would appreciate any help getting this done.
The answers is to edit the query and include the missing columns so that they are available to the report.
For non-selected query columns, the use of the word "hidden" is misleading. The way that SQL works--even beyond SQL in the overall concept of datasets--is that only subsets of data are requested in a query. If certain columns are not selected in a query, they are plainly and simply NOT available in the resultant dataset.
It may be possible to re-aquire the excluded columns with another query, but that still does not imply that missing columns were just "hidden". In the case of a subsequent query to get different columns of data, the database engine must re-analyze the new query, re-read the data, then compile the data from the new set of columns to be returned in a completely new subset of data. It is a complete round-trip process that is much more involved than just un-hiding the data.
Forms and reports are completely different types of objects that can mark fields as "hidden", but a query is not the same despite being displayed in a datasheet. Objects like Access Forms and Recordset objects in (VBA) code are designed to hold subsets of queried data, so they are able to temporarily hide (or ignore) or un-hide certain fields without re-querying the database. (Technically an Access Form has its own Recordset object for holding and managing queried data.)
Even though Access is "self contained" with both database and user-interface elements, it is still primarily a standard RDBMS (Relational Database Management System). The principle idea in efficient data handling of an RDBMS is to get only what you need for the current operation. Consider that SQL can be used to query data from a remote server. Even Access can get data from and update data on SQL Server, for example. If data fields were only "hidden" when not included in a query, that would imply that the entire database (or at least an entire table) would be passed back and forth, and that the only thing hindering getting at any column would be "making it visible" as though it is actually immediately available. That would be terribly inefficient both for memory and for remote communications.
I have a table of products, batches and their test results. The user will be selecting a product to view all the tests. A continuous form is displayed with the filtered results.
What I would like is another custom filter in the form header that will list only those batches that are already displayed in the current filter set. For instance if they choose to look at test results for Product X, the form lists all the tests for Product X which may contain many batches...
I would like to have just those batches that are for Product X in the CBObox so the user can select it and see only that set of tests.
From what I have found on the web so far, they seem to be displaying ALL batches and not just those in the displayed record set.
Is this possible and thanks in advance.
Is your database connected to sql server? If so, filter using the where clause in a sql string. If not vba is the answer to filtering based on this results. Do you have any pictures or sample code so I can help you out further. You could also set the record source of the combobox to the query with such filters applied.
I am trying to determine the best method of collecting a large list from a database and then displaying and filtering the results on the client side. Let me give a quick example:
Example: I've got a database with customer data and currently it contains around 2000 records. This number is constantly increasing. On my website I have a page that I want to be able to query said database based on information such as name, email, phone number etc. and of course display the results (when a user types in Smith it returns all records containing the name Smith). I am planning on using AJAX so that I can query the database and display the results on the fly similar to how google does it. When a user begins searching, results will start showing up on the page as they are found.
Possible Solutions:
Unfortunately I am stumped on how to go about implementing something like this. I am considering using a ValueList pattern. When the user first loads the page, should I be querying the database and storing every record in a collection and then searching that collection list and displaying the results on my jsp page? Essentially creating a java database. The thing I like about the ValueList pattern is that I take one huge hit on page load and dump the entire database in objects stored in a list. What if the database is larger though, say 2,000,000 records?
Or should I be using a simple DOA pattern without the ValueList and query the database for each individual search? This would result in a LOT of database queries, especially considering that I plan on returning results as the user types in the search box.
Edit: The more I think about this, the more it is an AJAX question. My biggest concern should be how to query my database while the user is typing. Do I set some sort of listener to listen for the user to stop typing and then perform the query?
I would use Solr for this type of task.
Fields, which you are going to use for searching should be indexed with Solr.
Then you do an ajax query to Solr and get the result. You can set the order, number of items per page and show results only for current page.
Solr has a lot of other features that can be useful for you.