Syncronize subform with main form

S

Song Su

I have 2 tables:
computer
software

and both have field called 'serial' with 1 to many relation (computer 1 and
software many).

I used wizard to create two forms:
frmComputerSingle (main form)
software subform (subform)

I converte one of the text field in main form to combo box called 'cboname'

When user select a new record in 'cboname' field, I want the subform to
syncronize it. I know it should be 'after update' event. but how to code it?

Thanks.

- Song
 
G

Guest

Hi Song,

If you have a mainform/subform setup within Access, you just need to set the
parent/child fields in the form properties and Access will keep the subform
synchronised for you.

Hope this helps.

Damian.
 
M

Marshall Barton

Song said:
I have 2 tables:
computer
software

and both have field called 'serial' with 1 to many relation (computer 1 and
software many).

I used wizard to create two forms:
frmComputerSingle (main form)
software subform (subform)

I converte one of the text field in main form to combo box called 'cboname'

When user select a new record in 'cboname' field, I want the subform to
syncronize it. I know it should be 'after update' event. but how to code it?

Assuming the combo box's BoundColumn property corresponds to
the serial field, you should be able to synchronize the
subform just by setting the subform control's Link Master
Fields property to the combo box and the Link Child Fields
property to the serial field. No code needed.
 
S

Song Su

Thanks for quick reply. The problem is the field on the main I converted to
combo box is NOT 'serial', the primary key. It's 'computername' field. I
want users to select a 'computername' and I want subform to display it's
software.

- Song
 
M

Marshall Barton

Yes, of course. BUT, The combo box's RowSource query should
include BOTH fields:

SELECT serial, computername
FROM computers
ORDER BY computername

Then set the combo box's BoundColumn property to 1
and the ColumnWidths property to 0;

This allows you to see the computher name AND use the serial
value as the Link Master to synchronize the subform as I
described earlier.
 
S

Song Su

Hi, Marsh:

Control Source: ComputerName
Row Source:
SELECT Computer.Serial, Computer.ComputerName
FROM Computer
ORDER BY Computer.ComputerName;

bound column: 1
column width: 0; 0.9

When I select from combo box, (I can see only computername field) record
selector becomes a pencil and nothing moves.

when I use navigation at bottom to go to different record, it moves and
syncs (but the combo box always blank.

what did I do wrong?

- Song

Marshall Barton said:
Yes, of course. BUT, The combo box's RowSource query should
include BOTH fields:

SELECT serial, computername
FROM computers
ORDER BY computername

Then set the combo box's BoundColumn property to 1
and the ColumnWidths property to 0;

This allows you to see the computher name AND use the serial
value as the Link Master to synchronize the subform as I
described earlier.
--
Marsh
MVP [MS Access]


Song said:
Thanks for quick reply. The problem is the field on the main I converted
to
combo box is NOT 'serial', the primary key. It's 'computername' field. I
want users to select a 'computername' and I want subform to display it's
software.


"Marshall Barton"wrote
 
M

Marshall Barton

It looks like the problem is that the combo box is bound to
the computer name field. It should be bound to the serial
number field. The computer name is just for the convenience
of humans. It's not even clear why you would want this to
be a combo box.

The main form is used to enter/edit/view data about a
computer so you should have separate text boxes for the
serial number and computer name. A combo box is only
appropriate for selecting from a list of computers and, if I
understand what you are doing, you are already looking at
the specific computer record.

The only situation I can think of where a combo box would
make sense is if it is in the main form's header section and
only used as a search mechanism to find a computer's record.
In this case the combo box must be **unbound** so it doesn't
modify any data in the table.
 

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