Edit: I have one column in the table. For example its call "Title". This column has a combobox that has list of items like "Best In Show", "Best In Group" etc. I want to select one of the following drop-down list of items was a different text. For example: I have selected "Best In Show" but in column its should looks like "BIS!"
Of course that other text that will replace the original in the drop-down list is also known that I can post in SQL-query or in macros or in other tables or elsewhere
Let me know if you need more info. Thanks.
Use as the record source for the combo a table/query/value list with two columns, the first with the abbreviation, the second with the display value.
Set the number of columns in the combo to 2, and set the Column Width of the first column to 0.
This will then show the display value for the actual value in the database.
Also see the last answer MS Access Dropdown List/Combo Box
Let's say you have a Film (ID, Title, Abbrv) table and a Person (ID, Name) table.
And you also have a union table Person_Film (PersonID, FilmID)
For the union table, Person_Film, you'd like to select a person based on his/her name, and a film based on its title, but you'd like to see the abbreviation instead.
What you do is to use the Lookup wizard on your Person_Film.FilmID field. You do so by choosing "Lookup wizard..." instead of a data type when in design view for the forementioned table and field and choosing the first option, "I want the lookup column to look up the values in a table or query"
If the wizard complains saying that there exist a relationship based on that field, just go to the Relations screen in the Tools menu, delete the relation (look for the field in the table) and retry. Don't worry: The wizard will re-create the relation in the end.
You select the Film table as row source, and select ID, Abbrv and Title (in that order). Leave the option to hide the key column checked, as recommended.
The result is something like this:
Related
I'm completely new to creating MS Access databases, so please bear with me while I ask my (probably silly) question.
I have a table for commodities that also groups them into CropGroup and Class, and every commodity would also be considered 'Any food'.
Commodity table:
I would like to add one entry (maybe in a form?), with fields like 'Country' 'Commodity' 'Metal' 'Limit' with all fields identical other than the commodity. Rather than entering these manually for each commodity, is there a way that I can specify the country, metal and limit, select 'Fruit' or 'Anyfood' to automatically create a record for each commodity associated with these terms, so it looks similar to this? Doing this would save me hours if not days of work in the long term.
Output table:
Any suggestions or pointers in the right directions would be much appreciated!
Cheers,
Sophie
You can set default value for text or comboboxes in data entry form.
So, you will set default value for each text box individually. When you you will run the form, text boxes will fill with default values automatically. If need you can then change values as per your need. As per my above screenshot, when you run the data entry form it will look like-
If anyone comes across to this question later, I was able to solve this perfectly with a relatively simple SQL query in the end:
INSERT INTO MetalLimits ( Country, Commodity, Element, [Limit(mg/kg)] )
SELECT Country, Commodity, Element, [Limit(mg/kg)]
FROM (SELECT Commodity FROM _CommodityList
WHERE (([_CommodityList].CropGroup) Like [Enter CropGroup] & "*") AND
(([_CommodityList].Class) Like [Enter Class] & "*")) ;
This allows manually entering Country, Element and Limit(mg/kg) as per the table rules (for MetalLimits table) in separate prompt pop-ups, and select the commodities based on the pre-defined CropGroup and Class (from _CommodityList) in another pop-up.
Table1 has a field ItemID; I use that to lookup the corresponding record in Table2, which has fields ItemID and ItemDescription.
My form uses Table1 as its Recordsource. I want to display ItemDescription from Table2 in a combobox or textbox.
From what I've read, there are several ways to accomplish this, but I can't tell which is considered the standard method:
Add a subform to the form, with Table2 as its Recordsource.
Make a query combining Table1 and Table2, and use the query as the form's Recordsource.
Use a SELECT statement as Table1's Recordsource that pulls in fields from both tables. (Basically, using the aforementioned query in a different way.)
Use DLOOKUP as the Control Source of the textbox, something like
=Dlookup("ItemDescription","Table2","ItemID = Forms!MyForm!ItemID"
In my case, I expect I'll have to link Table1 to about five different lookup tables; and some of those may have lookup tables of their own.
What is the best way to show data on the form from these multiple tables?
Add a subform to the form, with Table2 as its Recordsource.
This is an overkill. Do this only for detail records where the main form is on the one side of a one-to-n relation.
Make a query combining Table1 and Table2, and use the query as the form's Recordsource.
This works only one way and is okay for a read-only form. But you cannot edit the value and the value will not change when you make edits to another field containing the id
Use a SELECT statement as Table1's Recordsource that pulls in fields from both tables.
Same as above.
Use DLOOKUP as the Control Source of the textbox.
This works well and you can update the textbox with textbox.Requery() when necessary. But of course, you cannot edit the value.
An option that works for displaying AND for editing the value is to use a ComboBox. Setup the combo box like this:
(in the Data section) Set the Control Source to ItemID. This is a column of the Record Source of the form.
Set the Row Source Type to Table/Query
Either specify a query name or a SELECT statement as Row Source. Select the Id as first column and the display name as the second. E.g.
SELECT ItemID, ItemDescription FROM Table2 ORDER BY ItemDescription;
Set the Bound Column to 1 (the ID column)
Set Limit To List to Yes
(in the Format section) Set Column Count to 2
Set Column Widths to 0 to hide the first column with the Id. You can specify a comma or semicolon delimited list of column widths here if you want to display several columns.
You can specify a higher number of rows in ListRows than the default 8 if you want.
Now the combo box displays ItemDescriptions automatically and is editable. I.e. you can select another Item from the drop down displaying ItemDescriptions and the ItemID on the form will be updated.
I have a query with [Which County?] as its Criteria. So it's already asking the user for the county it's to filter its results by.
I would like the input box that the user types the county name into to be a list box or combo box. Otherwise, I see a lot of typos being a regular annoyance.
Use a list box whose control source is a table that only contains the options you want the user to select from. There should be a table relationship between the table with the available country options and the table with the field you are filling in the form.
I am trying to create a report putting a field called contact which has the name of a person. This name is linked directly to another table where I keep all the contacts.
For some strange reason, when I include this name (which in query view displays as the name of the contact), instead of the name appearing, the unique ID number is shown on my report.
As mentioned in the article cited in the above comment, you can use a Combo Box control on your report to do the lookup for you. To see how this can be done, create a new report based on the table containing the lookup field, then drag and drop that field onto the report. That will create a Combo Box control with properties that look something like this:
Row Source: SELECT [Clients].[ID], [Clients].[LastName] FROM Clients;
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
You could use a similar Combo Box control on your actual report to display the client's name rather than their numeric ID value.
Another alternative would be to change the Control Source of the report's Text Box control to have it do a DLookUp() on the table. If the lookup field is named [client] then changing the Control Source of the Text Box to something like
=DLookUp("LastName","Clients","ID=" & [client])
would also work.
I wanted to add to the great answer by Gord:
When using a "web" database (started in Access 2007 I think), you cannot change a report's fields to ComboBox style, nor can you use DLookUp(). (web databases lack a ton of features)
The workaround for this, if you want to create a Web-Report that uses lookup fields, is to create a Web-Query first based on your Web-Table (all the Web-* stuff has a www planet icon over the logo, if you create a new Web-DB in Access 2007+ you'll see what I mean)
So, instead of Table -> Report, you'll have to do W-Table -> W-Query -> W-Report.
Then, the only thing you need to customize to get the data right is the W-Query. Start by trying to reproduce the look in the query to match what you want users to see in the report. Note that here in the query, lookups will work fine (instead of the unique ID's, you get field names like you want). However, this will not carry over to the report. To do that, you gotta get the actual text field name you want into the query:
You should already have one table in your query; start by adding the table that your first lookup field points to. For example, the table I want to print is called Stock_Boards, and it has a lookup field called PCBID_lookup that points to the table Stock_PCBs.
Since you're using lookup fields, there should already be a relationship line between the two tables when you add the second one. If there isn't, something has gone horribly wrong.
Now, see how that line connects two fields on the two different tables? For example, I've got my PCBID_lookup field on my Stock_Boards table, which connects to the ID field on my Stock_PCBs table. If I created a report from this now, PCBID_lookup would be a number, a number that correlates to the ID of a record on Stock_PCBs.
To fix it, I will add the name field I want to show up on the report. In my example, that happens to be a Part Number, rather than the ID. I add the PartNumber field from my Stock_PCBs table to the query, and remove the PCBID_lookup field of the Stock_Boards table from my query.
Since PartNumber is what I want to show up on my report, it effectively replaces the original field (PCBID_lookup)
Repeat for all lookup fields you want in your report.
I had 1 more: I removed the Status field of the Stock_Boards table (which was an ID/Lookup) and added the 'Status' field from the Status table (which was the actual text name)
When finished, your query should look exactly how you want the data to appear, without any special tricks or asking Access to do something unnatural. Save your query, and create a web-report from it. Done!
One of the parameters I have in my SSRS Report is called Customers. The user wants to be able to select multiple customers from a drop down list. Our customer list is over 500+ entries long. How can I get that many values in a drop down list. For that matter, how many values will a parameter handle? Is there a way to set the drop down list to be able to be typed over to prompt values? An example of that last question would be like how on most forms that ask for the state you live in, you can click on the list and type "TX" and it will move down to Texas instead of having to scroll down. I hope that makes sense. Thanks for all your help in advance!
You cannot have the parameter's field to behave with Autocomplete text.
And I agree that having 500 values in small field is not user friendly.
My suggestion is to split the parameters into 2-4 different parameters (in order to make the customer search more easy), each parameter will have the customers name according to the ABC (for instance the first params will contains the customer names from A-I,second J-R,last S-Z)
If so, your query should look like the following:
SELECT customerName,customerAddress,customerCity,...
FROM customerTable
WHERE (customerID IN (#customerParam1) OR customerID IN (#customerParam2) customerID IN (#customerParam3))
I don't know the how to do the second part with typing in a value but I can help with how to setup the drop down list. First write a query that selects the customer name and unique value for the customer.
Example:
SELECT CUSTOMER_NAME, CUSTOMER_ID
FROM CUSTOMER_TABLE
Then add the parameter and select your data type and the check box that says "Allow multiple values". Then in the properties click the "Available Values" tab. Once that opens select "Get values from a query" and select the the query you just wrote. Once that is selected go to the "Value" field and select the unique value from your query and for the "label" field select the customer name and they should all show up.
When using the values from the parameter in your main query you will need to make sure you use the IN function and not =. This is because you are not getting just one value back but all of them at once.
Example:
SELECT CUSTOMER_NAME,CUSTOMER_ADDRESS,CUSTOMER_CITY,...
FROM CUSTOMER_TABLE
WHERE CUSTOMER_ID IN (#CUSTOMERNAMEPARAMETER)
The name of the parameter is what variable name you need to use.
Also just another tip you can have them all default to selected by going to the default values and select "Get values from a query" and select your query and unique value again.
Also I don't think there is an issue with a number of items limit on the list box. I've had it up to almost 1,000 and had no issues.