Adding New Records to a Table Using Subforms

G

Guest

I currently have a form with a combo box that displays employee ids. The
source for the combo box is a query on table employees. I also have a subform
which is bound to table employees. I control the records displayed in the
subform using the combo box by setting the LinkMasterField and LinkChildField
of the subform. This all works fine. What I would like to do is use the
subform for both displaying existing records and adding new records. I would
like to have a blank or null value in the combo box that the user can select.
Once the blank employee id is selected the subform would then accept values
for a new record.

How can this be coded? Your reply would be appreciated.
 
G

Guest

Hi gaugust,

You could replace your current strategy with using an after update event to
move to the correct record, instead of having your combo box linked with the
link master/child field properties. That way, simply moving to a new record
would be enough.

To find a record, use this:

me.subformname.form.recordsetclone.findfirst "[ID] = " & me.cboSelectedItem
me.subormname.form.recordset.bookmark = me.subformname.recordsetclone.bookmark

Hope this helps.

Damian.

ps: Of course, if you unlink the combo from your subform, there's really no
need to use a subform at all - just have an unbound combo on your form with
your employee details to "jump" to the correct record.
 
G

Guest

Replaced current strategy with unlinked combo box to move to correct record.
Thanks.

Damian S said:
Hi gaugust,

You could replace your current strategy with using an after update event to
move to the correct record, instead of having your combo box linked with the
link master/child field properties. That way, simply moving to a new record
would be enough.

To find a record, use this:

me.subformname.form.recordsetclone.findfirst "[ID] = " & me.cboSelectedItem
me.subormname.form.recordset.bookmark = me.subformname.recordsetclone.bookmark

Hope this helps.

Damian.

ps: Of course, if you unlink the combo from your subform, there's really no
need to use a subform at all - just have an unbound combo on your form with
your employee details to "jump" to the correct record.

gaugust said:
I currently have a form with a combo box that displays employee ids. The
source for the combo box is a query on table employees. I also have a subform
which is bound to table employees. I control the records displayed in the
subform using the combo box by setting the LinkMasterField and LinkChildField
of the subform. This all works fine. What I would like to do is use the
subform for both displaying existing records and adding new records. I would
like to have a blank or null value in the combo box that the user can select.
Once the blank employee id is selected the subform would then accept values
for a new record.

How can this be coded? Your reply would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top