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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code for yes/no field on a form 1

Status
Not open for further replies.

lr999

Technical User
May 16, 2011
30
US
Could you, please provide a sample of an OnClick code for a yes/no
field on a form. When I'm trying to sum on my report this 'Verified' field, I get the words 'yes' or 'no', instead of counting, if the Verified Field is checked -it's a Yes, If it's not checked - it's a No. In Table 'Verified' field defines as(Yes/No). Do I make sence, I'm just starting out. thanks
 


IR...

You've posted a similar question in SEVERAL different forums and threads.

Why post again? Did you not get your question answered?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
No I didn't get, because I didn't explain it right
 


Well then, get your thought together and post your question IN ONE THREAD--your FIRST, where addressed.

And PLEASE do not do this shotgun of same issue, slightly differnt twist, NEW THREAD ever again.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That is some help you provided, thanks!!!
 
I always thought it kind of silly for Microsoft to define a field type as 'Yes/No' when 'True/False' is much more descriptive (and intuitive) to use. However, they are equal. As you pointed out, a Checked state = Yes and Unchecked = No. Logically, Yes = True and No = False. Numerically (which is how it is really stored) True = -1 and False = 0. Therefore:

Yes = True = -1
No = False = 0

Using this, if you know how many records you have and SUM the approprite Fields in the Report you can tell how many of each you have. For example, say you have 100 records and 25 are 'Yes' and 75 are 'No.'

The Count will be 100 (the total number.) The Sum will be -25 (the number of 'Yes' records * -1) and the difference will be 75 (the number of 'No' records) derived by using (Count - Abs(Sum)) or (Count + Sum) since we know we are dealing with a negative number. You get:

Count = Total Records
Abs(Sum) = 'Yes' Records
Count - Abs(Sum) = 'No' Records

Piece of cake? Right?

Now -- don't use On_Click, put the Count and Sum values into your TextBox controls on your form or report and set the ControlSource to equal the Sum or Count. In the Properties Box set the ControlSource for the TextBoxes to:

"=Count(Verified)" for the Total
"=Abs(Sum(Verified))" for the 'Yes' count
"=Count(Verified) + Sum(Verified)" for the 'No' count.

 

Seems sonewhat similar to a previous reply in another thread posted by the OP...
[tt]
sum([fieldName]) * -1 : total true records
sum([fieldName] + 1) : total false records
count([fieldname]) : total records
[/tt]

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I have done a lot of Adult Training classes for people in highly technical fields (in Nuclear Power Plants.) I am used to explaining in depth, rephrasing and repeating myself until the concept sticks.

I think it is harder than teaching Elementary School... not so sure about High School, though. ;-)
 
sorry not working both ways:
"=Count(Verified)" for the Total
"=Abs(Sum(Verified))" for the 'Yes' count
"=Count(Verified) + Sum(Verified)" for the 'No' count. or

sum([fieldName]) * -1 : total true records
sum([fieldName] + 1) : total false records
count([fieldname]) : total records
 
Then you need to show us your code with a very detailed description of your file structure and the form you are using, because I just got it to work just fine for me.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top