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!
Related
I've run into a bit of a snag with a project I'm working on, and being new to Access I don't know if what I want to do is possible without VBA. I've looked around but all I can find are answers related to showing multiple columns, not controlling multiple fields in my DB.
To paint a picture I have a mapping system set up in my DB to help me distinguish the name and type of data is held in a table.
The setup is as follows:
-Data table is "LineItems" with an ID and the line data (think typical excel format)
-Mapping table is "LineItem_Mapper" with LineItem_ID, DataType, and Entity_ID
-A helper table "Data_Type" with ID and Name
-two "Entity" tables with differing properties both have ID and Name
The reason for the split is on data type is that the two types of data behave differently. One type has a parent child relation, and the other is a standalone row. I want to preserve this structure in my DB and feel I have done so with this mapping.
Now, on to the issue I'm running into. In my Access data entry form I want to use a combo box, as the options a user may chose for each line when entering are finite. However, this combo box is affecting the Mapping table above. I have been able to populate the box with my desired list with a custom query built from my 2 entity tables, but I don't know how to get Access to create or update the Mapping table using this box.
what I want to happen is when I chose something in the box, a line is created (or changed) in the mapping table with all 3 columns being populated. first the LineItem_ID for the line I am populating, and then the DataType and Entity ID to reflect the proper mapping.
Can Access do this on its own? Or do I need to do this with VBA?
As requested by the OP converting my commend as an answer (with a little bit more detail):
By far your best option is to use VBA. I doubt there is another way and even if there is it would be so convoluted it would be unworkable and unmanageable.
This should get you started:
In the combo box properties go tot the events tab and in After Update or On Change (look up the difference between the two events to see which behavior you prefer) click the down arrow and select [Event Procedure], then click on the … button. This will create a VBA module for you complete with the function that runs when the selected event is triggered.
You can use DoCmd.RunSQL "[Access SQL INSERT statement]" to add records to tables.
You can use Me.[MyComboBoxName] to get the current value of the combo box. Similarly the value of anything else in your active form.
You can use DLookup to get the value of any record in your tables.
Hopefully these will give you a relatively quick start.
I'm facing an issue with Access Comboboxes that may be a terrible idea or be an improper use of the tool.
Let's say I have a form that shows metadata of a "Report" (things that are common in the report from day to day like reporter, project, target due date, expected total cost, etc...) with a Continuous subform of line items that are being reported (like cost of labor, materials, overhead expenses, etc)
In the backend I have 2 tables to represent this. The "Metadata" table and the "line items" table. When trying to capture individual items being reported the reporter is free to name the item as they see fit, however, in the system we want to map that reporter item naming to our internal item naming.
In order to do this I have a few helper tables and a mapping table to create this link. An 'Internal Line Item" table, a "DataType" table and a "Line Item Mapper" table.
The structure would look as follows:
- "Line Item" table with ID, Name, Metadata_ID and data (typical excel format)
- "Metadata" table with ID, and metadata common to all reports
- "Internal Line Item" table with ID and Name
- "Line Item Mapper" table with Internal_ID, LineItem_ID and DataType
- "DataType" table with ID and Name
So on to what I am having trouble doing.
I want to display a combo box in the subform for each row and the drop down will have a list of possible internal names that can be selected. I thought that by using an unbound box I could do this, but found that each row would get a copy of the same box (thus changing the selection for all rows at the same time).
I then tried to bind the box to the recordset using the ControlSource, but it changed id numbers when doing so (obviously not ok).
I then thought to tie the box to the Mapping table itself, but don't know how to couple it to the recordset as well...
What I want to do is bind this box to the recordset without allowing it to change any data in the "List Item" table because this box is meant to change the mapping table. I could then use the OnChange event to populate or update the mapping table with the proper data.
Is it possible to create such a binding (where the control is tied to a recordset, allowing me to get the LineItem ID, but not able to change the recordset while still allowing the user to interact with it)? Or is there a better way to approach this issue?
Turns out that I was just doing something foolish with my data model that lead to my troubles.
the full answer may be found here: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_access-msoffice_custom-mso_2013_release/bind-a-control-without-data-alteration-access-2013/51a98460-6e1a-425d-8f7b-eba5f2825ba9?tm=1552503037022&auth=1&page=2
but the short of it is that I was improperly placing all my FK's in a single table trying to make a form of "mapping" table. I have since corrected my structure and have gotten my combobox to work as intended.
So, I had lookup fields on my tables. I have recently learned that this is a bad idea. So, I'm trying to convert them to lookup fields in the forms that fill those tables.
The lookup list is drawn from another table with the individual values. On the table, I went into design view under the lookup tag and changed "combo box" to "text box." The fields that were previously lookup fields now display the "key" of the item that was displayed previously in the field.
The form still shows the correct lookup value but the associated table no longer does it instead shows the number associated with the value and not the value. What do I need to do to fix this.
I guess my question boils down to not knowing how to link a lookup field in a form to a text field in a table.
You don't need to change your forms, just update your tables - change lookup from combobox to text box, you did this correctly.
Existing forms should work as usual, with comboboxes, settings for those comboboxes were copied from table settings and not liked to table settings anymore.
In new forms you'll need to do the same manually: after placing the field to the form convert it to combobox then setup correct Row Source, Column Count and Column Widths properties of combobox.
If I have a lookup field in Access with the first (bound) column hidden by setting field widths to 0";1", is there a way to see the real underlying value of the field without having to change the formatting of the lookup column?
I don't believe there is a way to access the available values without editing the lookup column.
With that said, I would point out the following:
Changing the formatting of the lookup column only impacts 2 things.
When you navigate the records from the table view you will see the new definition.
Any forms created in the future will now inherit the new definition.
In other words, changing the formatting of the lookup column doesn't impact any forms you may have already created based upon that field.
You can have a more descriptive description in your table that is completely separate from the definition in your forms.
If you want to know all of the values I suggest that you edit the drop down to show a concatenation of columns 1 and 2.
For example, lets say you had a value list of
1;foo;2;bar
The value list could be changed to
1;1-foo;2;2-bar
Then you know at a glance what the "hidden" field value represents. (The same could be done if the record source is a query.)
Turns out that there is a very simple way to do it. In the query, go to field properties and click on the "Lookup" tab, and choose textbox.
I am new to Microsoft access, and I am trying to make a report from the data in 2 tables. I am using text boxes and setting the control source to the value from the table in the property sheet. All but one works fine, the one from the other table. The the value pops up with a "Enter Parameter Value" then the name of the main table when I switch to report view. The control source for the text box is "=[Main table]![Due date]" I made it with the little Expression maker in Expression builder. What am I doing wrong?
I found something close but it did not help me fix it link.
A form/report can only have one Record Source. Create a query that combines the two into a single query, and then use that as the form/report's Record Source.
If you are creating a form and you want the underlying table to be editable, join the tables together and make sure each of them has a primary key.