Populate bound textbox with value from mainform combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
Thanks Sprinks

Sprinks said:
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?

No relationship implemented (AFAIK). The main form is intended as a context
memory jogger for a user filling out a log, and is populated using a query
for an unbound combo box:
SELECT task.task_name, task.task_id, task.job_id, task.comments FROM task
WHERE (((task.job_id)=Forms![Time log]!cboJob) And ((task.completed)=No))
ORDER BY task.task_id;
(I have no idea why I wrote the query to select the task_id as the second
column :) )

The subform is intended for data entry into the log table, which is in a
one-to-many relationship with the task table, and I want to insert the task
id automatically into the log form once the task id was selected from the
main form lookup. (Don't know how to reference the column in a query)
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.

No primary key - just unbound text boxes. Probably this was the problem.
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.

Task table:
task_id primary key,
task_name
job_id
(etc)

Am I making this too complicated? Maybe the lookup combo boxes could be on
the log subform?

Should I use an event?
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.
 
Back
Top