Link to home
Start Free TrialLog in
Avatar of Donna Kainer
Donna KainerFlag for United States of America

asked on

Checkbox Validation Using SQL Code

I am trying to run some VB validation code when a Checkbox (PrimaryAcct) is changed. The Checkbox appears as part of a Repeater and is bound to a field (CAddr_PrimaryAcct) on a SQL table. For the group of records displayed by the Repeater (based on the Repeater record source being filtered), I need to ensure that one and only one record has the CAddr_PrimaryAcct field checked.

For example: The Repeater is displaying 3 records and one of them has the PrimaryAcct Checkbox checked. If the user attempts to add a new record and checks the PrimaryAccount Checkbox, I want to produce an error message saying that a PrimaryAcct has already been selected.  

I know that I can use the OnCheckedChanged method of CheckBox to call the subroutine to do the validation, but how do I cancel the change to the Checkbox if I find that there is already a record with the field checked?
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Why not run a SQL query when the page gets loaded to see if the PrimaryAcct has already been populated, if it has, then disable the CheckBox, if not, then the CheckBox is enabled.
ASKER CERTIFIED SOLUTION
Avatar of Donna Kainer
Donna Kainer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Donna Kainer

ASKER

I had to read between the lines but the solution referenced solved my problem.