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!

Checkbox control source problem

Status
Not open for further replies.

jack1080

Programmer
Jun 2, 2007
34
0
0
MY
For the following code chk is a check box, ischecked is a yes/no field.

Dim sSQL as string
sSQL = "Select [ischecked] from tbluser where userId='abc'"
chk.ControlSource = sSQL
chk.Requery

But when I run the following vba code, no matter ischecked is yes or no, it always shows me the checkbox is unchecked. Am I doing anything wrong? If yes how to correct it?
 
Perhaps this instead ?
chk.Value = DLookUp("ischecked", "tbluser", "userId='abc'")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, but I need the value to be updated to the database.
If the user checked the checkbox update yes, else no.
 
updated to the database

Then use an UPDATE query instead of a SELECT query?

Code:
Dim sSQL as string
sSQL = "Update tblUser Set [ischecked] = [ControlOnForm?] where userId='abc'"

Additionally, do you really want the userId hardcoded or do you need to get that from the control on the form too?

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
Hi lespaul,

Do you mean to bind the following sql to control source?
sSQL = "Update tblUser Set [ischecked] = [ControlOnForm?] where userId='abc'"

>>
do you really want the userId hardcoded or do you need to get that from the control on the form too?
<<
ans: need to get that from the control on the form
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top