by TWFydml » Wed, 23 Mar 2005 23:37:02
Sam,
Firstpulls the first matching item based on the criteria provided, the
syntax being:
DFirst(expr, domain, [criteria])
In the example I gave {=DFirst("F1","table1","ID=" & [ID]} :
F1 is the name of the field in the (other) table from which you want to pull
the value associated with the ID of the item in the form data source.
Table1 is the name of the (other) table from which you want to pull the
value associated with the ID of the item in the form data source.
The ID in quotation marks (i.e. D= is the ID field in the form data
source.
The ID in brackets ([ID]) refers to the ID field of the form data source.
In your example:
=DFirst("Category","tblType","CategoryID=" & [TypeID])
Category would be the name of a field in a table (or query) which holds the
value you want to show when it CategoryID field is the same as the TypeID
for the current record of the data in the form.
In a sense, what your statement says is:
how me, in this textbox, the Category in the table, tblType, where the
CategoryID in the tblType table is the same as the TypeID of the record in
the table (for this form) I am currently looking at.
I hope that helps more,
Marvin
>
> Thanks Marvin, but could you please explain a bit more about what each of the>
> item is>
> I try to modify your line to suit my application, but it seems I don't>
> really understand how the line works..>
>>
> =DFirst("Category","tblType","CategoryID=" & [TypeID]>
>>
> What have I done wrong here?>
>>
> Regards>
> Sa>
> >
>>
> "Marvin" wrote>
>>
>> > Part 2>
>> > (Continued>
>> > e.g>
>> > In the control source box for the textbox on the form, insert something lik>
>> > =DFirst("F1","table1","ID=" & [ID]>
>> > That will pull the value in the F1 field corresponding to the current>
>> > record into the textbox.>
>> >>
>> > Note: It's not a very efficient way to display the associated data. It would>
>> > probably be more efficiaent to bind the control>
>> >>
>> > Good Luck>
>> >>
>> > Marvi>
>> >>
>> > "Sam Kuo" wrote>
>> >>
>>>> > Hi>
>>>> >>
>>>> > I have a table tblCategory with 2 fields: CategoryID and Categor>
>>>> > and another table tblType with 3 fields: CategoryID, Category and Typ>
>>>> > and a form frmType based on tblTyp>
>>>> >>
>>>> > 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 hel>
>>>> >>
>>>> >>
>>>> >>
>>>> >>
>>>> >