Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use checkbox control as option button 1

Status
Not open for further replies.

tlafferty

Technical User
May 14, 2014
11
0
0
US
I have a check box control named Primary tied to table field named Primary with a datatype of Yes/No. The check box is part of a form that displays in continuous mode. How do I code so that when the user sets the Primary check box to True that all other records (other than the current record) have the Primary set to False? In other words, I only want to allow one Primary at a time to be True.
 
on the after update event of the checkbox
I am going to assume you have some kind of primary key. I will assume it is numeric. if it is text then sorround it with single quotes.
Code:
dim PK as long
dim strSql as string
pk = me.yourPrimaryKeyField
'if text, Pk = "'" & PK & "'"
strSql = "UPDATE yourTableName SET Primary = False WHERE yourPrimaryKeyField <> " & PK 
currentdb.execute strSql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top