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

Can this be done? 1

Status
Not open for further replies.

johnywest

MIS
Feb 19, 2003
15
US
On my Form I have a field that is a number. I want to put check boxes next to it lets say 4 of them. I want the number field to +1 for every box checked next to it.

i.e. if I had 3 boxes checked the value in the number field would be 3 and so on.

Is this even remotely possible.

Thanks
John

 
pff its even easy

name you checkboxes like this
chk_1
chk_2
...
in the afterupdate event of each checkbox put this

call calc_sub

and then add this outside the other events

private sub calc_sub()
const num_chk = 4
dim x,value as integer

value = 0
for x = 1 to num_chk
if me.controls("chk_" & x) = true then
value = value + 1
end if
next x
textbox = value
end sub Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Of couse it is possible, the question with progamming is never is it possible, but is it worht the effort.

Place this function anywhere on the form modual

Private Function countCks() As Integer
Dim cnt As Integer
If Me.Check0 = True Then
cnt = cnt + 1
End If
If Me.Check2 = True Then
cnt = cnt + 1
End If
If Me.Check4 = True Then
cnt = cnt + 1
End If
If Me.Check6 = True Then
cnt = cnt + 1
End If
countCks = cnt
End Function

<<<END CODE >>> do not include this line

On the after update event oof each and every check box place the following code

me!field1 = countCks()

<<<END CODE >>> do not include this line


Thats all it takes...Good Luck
ssecca
 
Keep in mind that Chrissie's solution only resolves if new true check boxes are being checked. The other solution handles the problem differently in that it looks evey time at all the check boxes and returns teh current count. Either one may be correct for your application just test the results to see which works the way you want.

Good Luck
ssecca
 
Great! Thanks for quick responses I will give it a shot and let you know how it worked out for me.

John
 
uhm secca read my code again it does exactly the same as yours

see the for next in it
Christiaan Baes
Belgium
&quot;What a wonderfull world&quot; - Louis armstrong
 
My applogies Chrissie you are absolutly right.

My regards one star for you!!!
ssecca
 
I appreciate all your help. But I am still having trouble with this code. I would just like to say I'm not computer illiterate but am somewhat of a novice with VB so I apologize for seeming so stupid.
Here's what I'm not understanding in both of the above codes you make ref: to puting a command in the onafter update event field---when I do this I get MS_access cannot find (in chrissies case) &quot; macro call calc_sub&quot; ( I am assuming that I make this entry in the properties box for the check box)and also I do not see how I get the number that the code generates into my text field where does the code do this am I supposed to sub my fieldname somewhere in the code? If you could give an example of code with the result field name (boxcount) maybe I would get a better idea or better yet one of you could send me a form with example code working [smile] This is like a puzzle for me and I really would like to solve it. I know I'm missing something just can't put finger on it. Once again I appreciate the help.

John
 
Well, with enough persistence I figured it out. I just had to re-school myself and got it to work. You guys have been great thank you very much.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top