What is the relationship between the RecordSource of the main form and the
RecordSource of the subform? Are there many logs for a single task?
If this is the case, this is a basic one-to-many relationship, which is
normally implemented by linking the subform to the main form by the latter’s
primary key and a corresponding field in the subform’s recordsource. From
what you’ve told me, I don’t believe that task_id is the primary key, and
therefore, you wouldn’t need it in the table underlying the subform—you can
get it anytime you need it in a query linking the two tables.
For example, an Orders main form would normally have an AutoNumber primary
key field, OrderNumber. The OrderDetails table that stores each line item,
also needs an OrderNumber field to associate the detail with the order. But
OrderDetails doesn’t need the CustomerNumber field, which is specified on the
main Orders form. A multi-table query will allow the information from all
relevant tables to be pulled together in order to print an invoice, annual
sales, etc.
What is the primary key of your main form’s record source? This is the
field that you should link to the subform, which may mean you need to add a
field to its underlying table. After the link is established, once the main
form has its primary key established, the value is also automatically stored
in the corresponding field of the table underlying the subform. You may
display it if you wish in the subform, but you don’t need to.
To establish the link, edit the form and select the subform. Show its
properties by selecting View, Properties from the menu. Set the
LinkMasterFields and LinkChildFields properties to the name of the field in
the main form’s source and subform’s source, respectively, that will store
the task_id.
If this doesn’t resolve your issue, please post the structures of the tables
underlying the main and sub forms, including their data types, and primary
keys.
Hope this helps.
Sprinks
kasab said:
The mainform (Time log) has a combo box (cboTask) containing task_id value in
column(1). A subform (log) has a bound field (task_id). I want to insert
the value from the cboTask.column(1) into the subform's task_id textbox. I
can display the correct value in an ubound textfield on the subform using
=Forms![Time log]!cboTask.column(1)
If I enter this into the Control Source property of the subform's task_id
textbox, the value is not saved to the table.
If I create a combo box on a query, an error is returned because the
cboTask.column function does not exist.
Would someone please let me know how this sort of thing is done
interactively, or using code, please?
Thanks in advance for your help.