[AccessD] Loading checkbox values into an array

Heenan, Lambert Lambert.Heenan at AIG.com
Wed Dec 5 16:26:07 CST 2007


Your example code does not actually display the value of blChk(intIndex)
anywhere. If you change your msgbox statement to...

MsgBox ctlIn.ControlType & " " & intIndex & " " & ctlIn.Value & " " &
blChk(intIndex)

... then yes, blChk(intIndex) is always false. But that's because you are
displaying the value of an uninitialized array element - because you
incremented the index before the MsgBox call. Like this...

Function LoadArray()

Dim ctlIn As Control, intIndex As Integer

Dim blChk(13) As Boolean

    For Each ctlIn In Me.Controls
    If ctlIn.ControlType = acCheckBox Then
       
       blChk(intIndex) = ctlIn.Value
        
        If MsgBox(ctlIn.ControlType & " " & intIndex & " " & ctlIn.Value _ 
			& " " & "Array value " & blChk(intIndex),
vbOKCancel) _ 
			= vbCancel Then Exit For
        intIndex = intIndex + 1
    End If
     
    Next ctlIn
End Function

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hale, Jim
Sent: Wednesday, December 05, 2007 4:31 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Loading checkbox values into an array



OK, the following function correctly identifies the checkboxes and their
values (-1 or 0) but for some reason
blChk(intIndex) = ctlIn.Value isn't working. No error, blchk is just wrong
(always false). 
blChk(intIndex) = cbool(ctlIn.Value) doesn't work either or setting blchk to
a variant. What am I missing? TIA Jim Hale

 Function LoadArray()
Dim ctlIn As Control, intIndex As Integer

Dim blChk(0 To 13) As Boolean

    For Each ctlIn In Me.Controls
    If ctlIn.ControlType = acCheckBox Then
       
       blChk(intIndex) = ctlIn.Value
        intIndex = intIndex + 1
     MsgBox ctlIn.ControlType & " " & intIndex & " " & ctlIn.Value
    End If
     
    Next ctlIn
    
End Function
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, December 04, 2007 6:39 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Loading checkbox values into an array

Give us a little more info.  Why do you need to load into an array?  An
array of what?

(air code)

function LoadArray (ParamArray varCtls() as variant)	
dim ctl as control
dim Arr(13) as variant
dim intIndex as integer
	for each ctl in varCtls
		arr(intIndex) = ctl.value
		intindex+=1
	next ctl 
	LoadArray = Arr
end function

?LoadArray(Chk1, Chk2, Chk3 etc etc)(0)

returns an array and displays the 0th element

Something like that?

You really should do some error checking to see how many objects varCtls
contains in case you pass in 14 controls (you'd get a runtime error).

John W. Colby
Colby Consulting
www.ColbyConsulting.com 
-----Original Message-----

***********************************************************************
The information transmitted is intended solely for the individual or entity
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of or
taking action in reliance upon this information by persons or entities other
than the intended recipient is prohibited. If you have received this email
in error please contact the sender and delete the material from any
computer. As a recipient of this email, you are responsible for screening
its contents and the contents of any attachments for the presence of
viruses. No liability is accepted for any damages caused by any virus
transmitted by this email.

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list