R
Ron
I have a feeling my problem is easy, but I'm hung up.
I have a many to many relation between tblItems (of jewelry) and tblStatus
("under construction," "consigned," "sold," etc.). I have a main form based
on tblItems and a properly functioning subForm based on the join table for
tblItems and tblStatus. In addition to the foreign keys, the join table
contains a date field - the date the status changed. IOW, for each item of
jewelry in the main form, the subform shows the status history.
The record source for the subForm is:
SELECT jtblItemsStatus.ItemsID, jtblItemsStatus.StatusID,
jtblItemsStatus.DateStatusChange
FROM tblStatus INNER JOIN jtblItemsStatus ON tblStatus.ID =
jtblItemsStatus.StatusID;
The subform consists of a combobox and a text box. The combobox bound
column is jtblItemsStatusID and the displayed text is the status field from
tblStatus. The text box shows the correspoinding date.
Now, I've placed two text boxes on the main form. (The idea is to display
current status at a glance.) In the first, I show the date for the *most
recent* status change. The control source is:
=DMax("[datestatuschange]","jtblItemsStatus","[jtblItemsStatus.ItemsID]=forms.frmMainForm.ID")
This works as intended. frmMainForm.ID is the PK for the current record in
the main form.
In the second box, I wish to show that same status field text from the
subform that corresponds to the latest date. I've played with DLookup (on
tblStatus) and with a query-subquery. No success, but I'm not sure whether
it's a syntax issue or completely wrong approach. (I've read that the third
expression of DLookup should be thought of as a query where clause, but I'm
confused about whether it can contain "join-like" references to other
tables.)
Would appreciate advice on the proper control source for the second textbox.
One thing I'd rather not do is derive it from the first textbox (in case I
change design later).
Many thanks, Ron
I have a many to many relation between tblItems (of jewelry) and tblStatus
("under construction," "consigned," "sold," etc.). I have a main form based
on tblItems and a properly functioning subForm based on the join table for
tblItems and tblStatus. In addition to the foreign keys, the join table
contains a date field - the date the status changed. IOW, for each item of
jewelry in the main form, the subform shows the status history.
The record source for the subForm is:
SELECT jtblItemsStatus.ItemsID, jtblItemsStatus.StatusID,
jtblItemsStatus.DateStatusChange
FROM tblStatus INNER JOIN jtblItemsStatus ON tblStatus.ID =
jtblItemsStatus.StatusID;
The subform consists of a combobox and a text box. The combobox bound
column is jtblItemsStatusID and the displayed text is the status field from
tblStatus. The text box shows the correspoinding date.
Now, I've placed two text boxes on the main form. (The idea is to display
current status at a glance.) In the first, I show the date for the *most
recent* status change. The control source is:
=DMax("[datestatuschange]","jtblItemsStatus","[jtblItemsStatus.ItemsID]=forms.frmMainForm.ID")
This works as intended. frmMainForm.ID is the PK for the current record in
the main form.
In the second box, I wish to show that same status field text from the
subform that corresponds to the latest date. I've played with DLookup (on
tblStatus) and with a query-subquery. No success, but I'm not sure whether
it's a syntax issue or completely wrong approach. (I've read that the third
expression of DLookup should be thought of as a query where clause, but I'm
confused about whether it can contain "join-like" references to other
tables.)
Would appreciate advice on the proper control source for the second textbox.
One thing I'd rather not do is derive it from the first textbox (in case I
change design later).
Many thanks, Ron