RE: How to lookup the corresponding field?
From: Sam Kuo (sam_cy_kuo_at_yahoo.com.(donotspam))
Date: 03/22/05
- Next message: Dan: "How do embed an excel object into a form"
- Previous message: Pradeep: "convert workgroup file from Access 2002 to Access 97"
- In reply to: Sprinks: "RE: How to lookup the corresponding field?"
- Next in thread: Sprinks: "RE: How to lookup the corresponding field?"
- Reply: Sprinks: "RE: How to lookup the corresponding field?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Mar 2005 04:01:03 -0800
Thanks Sprinks, that is very useful.
But I was hoping to use the Category textbox still (instead of combo box)
because I just want it to display the value, and not to give user the choice
of picking a different value from the Category combo box list.
I thought Marvin's approach of Domain Aggregate Function would do just that,
but I guess I don't really understand the line and hence unable to amend it
to suit my situation. Maybe you can help?
> 'Marvin' wrote:
> e.g.
> In the control source box for the textbox on the form, insert something like
> =DFirst("F1","table1","ID=" & [ID])
I rewrite it as so for my application, but it seems wrong...
=DFirst("Category","tblType","CategoryID=" & [TypeID])
Regards,
Sam
"Sprinks" wrote:
> Sam,
>
> You have what is a very common misconception about what should be *stored*
> in a table, and what is *displayed* on a form.
>
> Each table should define aspects of a single entity. For example, a
> category is completely defined by the tblCategory table--each has a unique
> numeric ID (the Primary Key), and a text description. Related tables such as
> tblType need only a numeric field in which to store the ID, called a Foreign
> Key. You do not need nor want to duplicate the category text field in the
> tblType table.
>
> Presumably, you have done so because you want to display this useful
> information on your form. You can do this in three ways. The first is by
> including the text field in the RowSource of a combo box, and setting the
> ColumnWidth property of the first column (the primary key) to 0". The combo
> box will display the first non-zero column width after the user makes a
> selection. This is what is happening in the first situation you described.
> The second way is display the primary key in the combo box by setting its
> width to something other than 0", and displaying the second column in another
> textbox by using the Column property of the combo box, setting its Control
> Source to:
>
> =MyComboBox.Column(1)
>
> 1 is used because the columns are numbered starting with zero.
>
> The third way is to base your form on a query based on both tables. Include
> a link between the primary key in Category and its related foreign key in
> tblType. Then include the text field from Category in the query. Once you
> base your form on the query, you can place this informational text field.
>
> The CategoryID textbox in frmType displays the ID because textboxes merely
> display the field to which they are bound (the ControlSource). Combo boxes
> display the first non-zero-width column regardless of which is the Bound
> Column.
>
> You can use any of the 3 methods above to display the text on frmType.
>
> Hope that helps.
> Sprinks
>
> "Sam Kuo" wrote:
>
> > Hi,
> >
> > I have a table tblCategory with 2 fields: CategoryID and Category
> > and another table tblType with 3 fields: CategoryID, Category and Type
> > and a form frmType based on tblType
> >
> > Category is auto number, and both Category and Type are text.
> >
> > I've managed to have the CategoryID field in tblType display Category values
> > instead of CategoryID values by setting its RowSource property to SELECT
> > DISTINCTROW [CategoryID], [Category] FROM tblCategory ORDER BY [Category];
> >
> > But the CategoryID textbox in frmType still displays CategoryID values, not
> > the Category values as it does in tblType! Can I make the CategoryID textbox
> > lookup the corresponding Category values?
> >
> > Many thanks for any help
> >
> >
> >
> >
> >
- Next message: Dan: "How do embed an excel object into a form"
- Previous message: Pradeep: "convert workgroup file from Access 2002 to Access 97"
- In reply to: Sprinks: "RE: How to lookup the corresponding field?"
- Next in thread: Sprinks: "RE: How to lookup the corresponding field?"
- Reply: Sprinks: "RE: How to lookup the corresponding field?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|