Lookup field appears as numerical values instead of text on Access report

元气小坏坏 提交于 2019-12-18 05:00:46

问题


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.


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/21269387/lookup-field-appears-as-numerical-values-instead-of-text-on-access-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!