Full Version: Shorter Way of Saying All true in a Procedure
UtterAccess Forums > Microsoft® Access > Access Forms
quest4
I want to do a check to see if all 8 of my chkboxes on the subform have been checked. I know I could use Me.chk1=True and mE.CHK2=True and so on, but is there a quick way of saying if all of the chkboxes in a subform = True then? thank you in advance for any help. giveup.gif
aoh
Not really, but you can say
If Me.chk1 and Me.chk2 ...
You don't need the "= True"
dannyseager
dim ctl as control
for each ctl in me.control
if ctl.controltype=acchkbox then
Me(ctl.value) = true
end if
next ctlset
ctl=nothing
I'm not certain that the "acchkbox" bit is the right term.
This checks all the boxes but you get the idea what to do.
quest4
Thank you for the response. That was what I was afraid of. Just hoping before I start typing. Thanks. cryhard.gif
quest4
Thank you Danny. I was just getting set to start typing. o!
Jack Cowley
Hmmm. 8 checkboxes? Are these 8 fields in a single record or are they 8 separate records related to another table? If they are 8 fields in a single record then you need to rethink your approach as you have 'repeating groups' in your table and that is a no-no in a relational database.
Just checking....
Jack
Larry Larsen
Hi Danny
omething like:
If ctl.ControlType = acCheckBox Then
PS: Jack has a good point..?
thumbup.gif
dannyseager
Thanks Larry.
After I had typed in what I did I thought it might be that but wasn't sure so didn't change it.
quest4
I already figured out the acCheckbox, but I am erroring out: Method or Data member not found. Here is what I have:
Dim ctl As Control
For Each ctl In Me.Control
If ctl.ControlType = acCheckBox Then
Me(ctl.Value) = True
Me!DateCompleted = Date
Else
Me!DateCompleted = Null
End If
Next ctlset
ctl = Nothing
DoCmd.Close
The debugger hi-lites this line:
For Each ctl In Me.Control
This is being run fron the OnClick event of a cmdButton, and all of the chkboxes are in the subform, if that is important. Thank you for the help. giveup.gif
Jack Cowley
If your code is in the main form then your code needs to refer to the controls in the subform. You code now refers to the controls on the main form... This site will give you the proper syntax to refer to the controls in the subform....
id you read my previous post about your yes/no fields being 8 fields in a record or 8 records? Just checking to make sure your data is normalized...
hth,
Jack
quest4
Thank you for the response, Jack. I have a copy of that sheet sitting in front of me, someone gave it to me a several months ago. I do use it alot and I made the change to this line:
For Each ctl In Me!fsubApprovals.Control
Then I got a new error on this line:
next ctlset
Invalid variable control reference. I understand what you are saying about the checkoxes, but I am using them just to filling some txtboxes and then to check and make sure everything has been checked. This is a glorified checklist in reality. Thank you again for the assistnace.
quest4
I took the set off of ctlset and it stopped erroring out, almost. Now if you click the cmdButton, you get a message, no debugger, object does not support this property or method. This is what i have modified it into:
If Me!fsubECNApprovals.Form!CMPCompleted = True Then
Dim ctl As Control
For Each ctl In Me!fsubECNApprovals.Control
If ctl.ControlType = acCheckBox Then
Me(ctl.Value) = True
Me!DateCompleted = Date
Else
Me!DateCompleted = Null
End If
Next ctl
ctl = Nothing
DoCmd.Close
Else
DoCmd.Close
End If
It works correctly if the CMPCompleted chkbox is NOT checked. It errors if it is, what did I do wrong? Thanks you for all of the help. giveup.gif
Jack Cowley
The code should read:
ext ctl
I think too that the first line should read:
For Each ctl in Me!subApprovals.Form.Controls
but I have not tried it...
hth,
Jack
quest4
That was interesting. I get the following messge, "The Control number that you specified is greater than the number of controls". No erros just the pop-up with the message. I did add a line:
If ctl.ControlType = acCheckBox Then
MsgBox ctl.Value
Me(ctl.Value) = True
Me!DateCompleted = Date
The msgbox did produce a -1. That was interesting also, but I am not sure yet what that means. Thank you again for all of the help.
quest4
This may help more.
Jack Cowley
Hmm. Try this but changes names as appropriate...
!--c1-->
CODE
Dim frm As Form
Dim ctl As Control
Set frm = [Forms]![frmMainFormName]![SubformName].Form
For Each ctl In frm.Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = 0 Then
    MsgBox "Missing data in " & ctl.Name
End If
End If
Next

hth,
Jack
quest4
Jack, again you the man. So using the number values of True and False does the trick, as well as full path names in the forms. Very interesting, thank you very much and again, as usual I have learned a couple more thinks, I appreciate the help. thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.