Checkbox on continuous form behave like option group

S

Scott

Hi all,
Here's the short question :)
I'm hoping someone can suggest an elegant way for me to 'simulate' the
behaviour of the radio buttons in the 'Option Group' frame on a continuous
form which contains a Checkbox on each line (record). (whereby only one
checkbox is/can be 'selected' at a time)

Here's the long version :)
I have a child form I am popping up, which is a continuous form, and allows
users to enter multiple alternative sets of address info (street, city,
postcode etc) which are stored in a 'tbl_addresses' table. This child form
is called from a button on a parent form called 'frm_clients' (data for
which is stored in tbl_clients) which contains all sorts of client info,
including one set of address info.

Each client can have several addresses, but only one is 'primary'. This
primary address is determined by checking a checkbox on the child form, and
then this address info is updated back to the parent form (and therefore
table)

I have all the code right for updating the primary address back and forth
between the two forms, but I'm trying to sort out some code to ensure that
only one address within the clients subset of addresses (determined by
unique ID numbers) can be selected as primary (at a time).

I was thinking that in the 'On click' of the checkbox, I could build a
dataset of the current clients addresses, set all the 'Primary' boolean
fields to False, and the set the current 'Primary' boolean back to True, but
this seems a bit clumsy.

If anyone has any suggestions, they would be greatly appreciated.

Thanks in advance
Scott
 
D

Douglas J. Steele

While not fool-proof (since the table can always be updated without using
the form), put code in the AfterUpdate event of the check box on the subform
so that if the current check box is True, you set the "Primary" field to
False for all relevant rows except the current one.
 
S

Scott

Thanks Douglas.
Can you suggest the best way, programmatically to set the rest of the
checkboxes for that client to false? I was thinking of doing something like
creating a recordset containing only the records to do with this client, and
then looping through to set them each to false, but I'm wondering if I'm
getting too complex there and missing a much simpler way to do it?

Thanks again.
Scott
 
D

Douglas J. Steele

Use an Update query:

UPDATE MyTable
SET PrimaryAddress = False
WHERE CustomerID = whatever
AND AddressID <> primaryaddress
 
S

Scott

Beautiful! Thanks again Douglas.

Douglas J. Steele said:
Use an Update query:

UPDATE MyTable
SET PrimaryAddress = False
WHERE CustomerID = whatever
AND AddressID <> primaryaddress
 

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