473,486 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to display text in a text box whose source is an ID number

11 New Member
I have the following table:

tblProduct: ProductID, ProductName

I would like to add a textbox in a form bound to ProductID. How do I do to let the text box show the ProductName, instead of the ProductID? Thanks in advance.
Sep 2 '08 #1
8 9322
Stewart Ross
2,545 Recognized Expert Moderator Specialist
It's usually done using a combo box whose row source is a query based on your product table. The combo would have two columns, the product ID and the product name, with the width property for the ID column set to 0 (hidden in other words).

The Access combo box wizard does this for you on a step-by-step basis.

-Stewart

PS the combo would be bound to field Product ID in the underlying table, just as you suggested in your question
Sep 2 '08 #2
yltang
11 New Member
It's usually done using a combo box whose row source is a query based on your product table. The combo would have two columns, the product ID and the product name, with the width property for the ID column set to 0 (hidden in other words).

The Access combo box wizard does this for you on a step-by-step basis.

-Stewart

PS the combo would be bound to field Product ID in the underlying table, just as you suggested in your question

Thanks Stewart,
Sorry that I didn't make my question more clear. Actually, there are two tables with the main fields as follows:

tblProduct: ProductID, ProductName, ...
tblOrder: OrderID, ProductID, ...

I need to have a textbox in the order input form "frmOrder" such that the ProductName will show up in the textbox. For some reasons, I can't use combo boxes. Sorry again and any further suggestions? Thanks.
Sep 2 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
A combo is the best solution here, but if you can't use one for some reason there are two other options:

(1) in your underlying query which acts as the rowsource for the subform you can join order and product together so that the product name is listed along with the product ID when the product ID is selected, which would allow you to place a bound product name textbox onto your subform, or

(2) you can place an unbound textbox on your subform and use the domain lookup function DLookup to lookup the corresponding product name for the product ID field. You would set the row source of the textbox to the following, choosing the first version if ProductID is a number or the second version if it is a string:

Expand|Select|Wrap|Line Numbers
  1. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
  2. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = '" & [ProductID] & "'")
In both cases you would also set the Enabled property of the textbox False and Locked True (to prevent users from trying to alter the contents). I also use a different background colour for lookup controls to differentiate them from user data entry controls.

-Stewart
Sep 2 '08 #4
NeoPa
32,556 Recognized Expert Moderator MVP
At its simplest I think you need to build your form on a query with SQL similar to the following :
Expand|Select|Wrap|Line Numbers
  1. SELECT tO.OrderID,
  2.        tO....,
  3.        tP.ProductName
  4.  
  5. FROM tblOrder AS tO LEFT JOIN tblProduct AS tP
  6.   ON tO.ProductID=tP.ProductID
  7.  
  8. ...
Sep 2 '08 #5
yltang
11 New Member
A combo is the best solution here, but if you can't use one for some reason there are two other options:

(1) in your underlying query which acts as the rowsource for the subform you can join order and product together so that the product name is listed along with the product ID when the product ID is selected, which would allow you to place a bound product name textbox onto your subform, or

(2) you can place an unbound textbox on your subform and use the domain lookup function DLookup to lookup the corresponding product name for the product ID field. You would set the row source of the textbox to the following, choosing the first version if ProductID is a number or the second version if it is a string:

Expand|Select|Wrap|Line Numbers
  1. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
  2. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = '" & [ProductID] & "'")
In both cases you would also set the Enabled property of the textbox False and Locked True (to prevent users from trying to alter the contents). I also use a different background colour for lookup controls to differentiate them from user data entry controls.

-Stewart
Got it! Problem solved. Thanks a million.
Sep 3 '08 #6
yltang
11 New Member
A combo is the best solution here, but if you can't use one for some reason there are two other options:

(1) in your underlying query which acts as the rowsource for the subform you can join order and product together so that the product name is listed along with the product ID when the product ID is selected, which would allow you to place a bound product name textbox onto your subform, or

(2) you can place an unbound textbox on your subform and use the domain lookup function DLookup to lookup the corresponding product name for the product ID field. You would set the row source of the textbox to the following, choosing the first version if ProductID is a number or the second version if it is a string:

Expand|Select|Wrap|Line Numbers
  1. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
  2. =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = '" & [ProductID] & "'")
In both cases you would also set the Enabled property of the textbox False and Locked True (to prevent users from trying to alter the contents). I also use a different background colour for lookup controls to differentiate them from user data entry controls.

-Stewart
One more question. If the DLookup fails to find a valid return value, the textbox will display "# Error". How to let the textbox display nothing in such a case? Thanks for your time.
Sep 3 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Dlookup itself returns null if it cannot match a value. The '#Error' value returned arises typically because the criteria value passed to DLookup is null (this will always be the case on a new record, for instance). To guard against this you can enclose your DLookup in an IIF statement to test for null and return a null in these circumstances like this:

=IIF(IsNull([ProductID], Null, DLookup(... as before ...))

-Stewart
Sep 3 '08 #8
yltang
11 New Member
Dlookup itself returns null if it cannot match a value. The '#Error' value returned arises typically because the criteria value passed to DLookup is null (this will always be the case on a new record, for instance). To guard against this you can enclose your DLookup in an IIF statement to test for null and return a null in these circumstances like this:

=IIF(IsNull([ProductID], Null, DLookup(... as before ...))

-Stewart
Problem solved! Thanks a lot, Stewart.
Sep 4 '08 #9

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

Similar topics

19
6850
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
0
5795
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
1
1178
by: philip | last post by:
hello, i am confused about the following aspx page, when the Submit button is clicked, the page will append a number to Label1, but i am wondering why the first row displays twice, would u please...
4
2728
by: rszebras | last post by:
I inherited a database (as a novice at Access) and need to modify it to make it more efficient, i.e., the assignment form needs to autopopulate with the client's name, address, phone number, etc.,...
5
2744
by: PHPBABY3 | last post by:
Hi, 1. I have two SQL tables. I will call them employees and departments: EMP: LAST_NAME, FIRST_NAME, DEPTNM DEPT: NUM, NAME Input: text string FIND Output: the LAST_NAME, FIRST_NAME...
3
1773
by: swinster | last post by:
Hi all, I have not touched access for a very long time and am attempting to help my nephew with his Video Rental Database. This is a simple three-table relationship database comprising a Video...
4
2402
by: rn5a | last post by:
A MS-Access DB has 3 tables - Teacher, Class & TeacherClass. The Teacher table has 2 columns - TeacherID & TeacherName (TeacherID being the primary key). The Class table too has 2 columns - ClassID...
6
5103
by: Gord | last post by:
I have a report whose Record Source I set in code when clicking on a command button on a form. This Record Source is a table that gets created by the code. I have a textbox on the report whose...
0
7094
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
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
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...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.