473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get field value from related table

Hi,

I am working with Access 2010 and I want to get a field value from an related table and put it into an text field in an report. I tried something like DLookup, but I get this error: #Type! (I am working with the dutch version).

Please give me another, working solution and instructions/code.
Jul 27 '10 #1

✓ answered by Stewart Ross

Sorry, but I can't tell from the screenshot - it's not got the resolution to let me see where you are typing this.

If you are using an unbound textbox then the property into which you type the =Dlookup expression is the control source for the textbox. As I have said, commas are the separators. Here is an extract from the MS Help entry for DLookup:

You can also use the DLookup function in an expression in a calculated control on a form or report if the field that you need to display isn't in the record source on which your form or report is based. For example, suppose you have an Order Details form based on an Order Details table with a text box called ProductID that displays the ProductID field. To look up ProductName from a Products table based on the value in the text box, you could create another text box and set its ControlSource property to the following expression:

=DLookup("[ProductName]", "Products", "[ProductID] =" _
& Forms![Order Details]!ProductID)
-Stewart

6 14339
Stewart Ross
2,545 Expert Mod 2GB
Sorry, but as you have posted no details of the field you are trying to look up, the table or query in which it is located, and the WHERE clause you are trying we can't help you. You should at least have posted the exact call you are using for the DLookup that fails!

Dlookup, like all the domain functions, is straightforward to use but it must be called in the correct format, of which this is just an example:

Expand|Select|Wrap|Line Numbers
  1. =DLookup("[YourFieldName]", "[YourTableName]", "somefield=somecriterion")
-Stewart
Jul 27 '10 #2
I am making an database to collect my school points. I have an table that is called subjects and a table ths is called tests. The subjects table has the full name of the subject, and in an report of the table tests, i want to get the full subject name, not just the id.

I tried it again with your code:
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Name]";"[Subjects]";"[Subject-Id]="+[Subject])
But he gives again this error: #Type!
Jul 28 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Not surprised - the arguments to DLookup must be separated by commas for a start, and you should use the ampersand operator to concatenate the value concerned onto the where-part string:

Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Name]", "[Subjects]", "[Subject-Id]=" & [Subject]
This should work OK if the [Subject] field is a number. If it is a text or alphanumeric value, you will need to enclose it in single quotes, like this:

Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Name]", "[Subjects]", "[Subject-Id] = '" & [Subject]& "'"
-Stewart
Jul 28 '10 #4
If I use comma's,he says that there is an syntax error.

Maybe I am typing it on the wrong place?I added a screenshot.

Naamloos.jpg
Jul 28 '10 #5
Stewart Ross
2,545 Expert Mod 2GB
Sorry, but I can't tell from the screenshot - it's not got the resolution to let me see where you are typing this.

If you are using an unbound textbox then the property into which you type the =Dlookup expression is the control source for the textbox. As I have said, commas are the separators. Here is an extract from the MS Help entry for DLookup:

You can also use the DLookup function in an expression in a calculated control on a form or report if the field that you need to display isn't in the record source on which your form or report is based. For example, suppose you have an Order Details form based on an Order Details table with a text box called ProductID that displays the ProductID field. To look up ProductName from a Products table based on the value in the text box, you could create another text box and set its ControlSource property to the following expression:

=DLookup("[ProductName]", "Products", "[ProductID] =" _
& Forms![Order Details]!ProductID)
-Stewart
Jul 28 '10 #6
@Stewart Ross Inverness
Thank you very much. It works now on the way I want.
Jul 28 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fons Roelandt | last post by:
Heelo, I have to Update all fields from a table with the values of a related table, i've tried some querys i found on the internet, but nothing seems to word, i even tried to lookup the value...
7
by: Amy | last post by:
I'm trying to add an autoincrementing id to a table based on an existing field Name, but Name has duplicated records. How can I do that in ACCESS? Thanks. Amy
3
by: Gerry Abbott | last post by:
Hi all, Im using the after update event of a field from a bound form to add records using the recordset object, to a related table. However i'm getting the 3201 error, telling me I must have a...
1
by: md7546 | last post by:
Hi, first time posting to this group, but I have followed advice and examples for several months, so thank you. I work for a small telecommunications company. I have a simple Orders database...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
4
by: Michael R | last post by:
Or is it not necessary to have that option on the related table field, as the primary table indexed field does that job? And is it a necessity to have the related table field to be indexed if I...
11
jhowells28
by: jhowells28 | last post by:
I have a subform for data entry purposes and I would like to populate a text box with a "suggested" value that will be pulled from a related table. I say "suggested" because the information stored...
4
by: billa856 | last post by:
Hi, I want to know how can we set the value of Textbox = value of field in table when we select a value form combobx. example i have a table customer CID CNAME CSALARY 1 Billa ...
2
by: jaad | last post by:
Ok I am seriously starting to scare myself with this one. I've only been dealing with Access 2007 since August of 2009 and being a newbee I made a lot of mistakes but learned a lot since then. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.