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.
8 9322
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
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.
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: - =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
-
=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
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 : - SELECT tO.OrderID,
-
tO....,
-
tP.ProductName
-
-
FROM tblOrder AS tO LEFT JOIN tblProduct AS tP
-
ON tO.ProductID=tP.ProductID
-
-
...
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: - =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
-
=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.
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: - =DLookup("[ProductName]", "[tblProduct]", "[ProductID] = " & [ProductID])
-
=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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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.,...
|
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...
| |
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...
|
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...
|
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...
|
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,...
|
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,...
|
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: 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...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |