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

code check / help

Status
Not open for further replies.

thegameoflife

Programmer
Dec 5, 2001
206
US
I have 7 check boxes. I'm wanting "b" to equal only the boxes that are checked. So far I can only set "b" equal to all the boxes. If there is an easer way of doing this PLEASE let me know.

Code:
    b1 = Me.Check17
    If b1 = -1 Then
        b1 = 1
    End If
    
    b2 = Me.Check19
    If b2 = -1 Then
        b2 = 2
    End If
    
    b3 = Me.Check21
    If b3 = -1 Then
        b3 = 3
    End If
    
    b4 = Me.Check23
    If b4 = -1 Then
        b4 = 4
    End If
    
    b5 = Me.Check25
    If b5 = -1 Then
        b5 = 5
    End If
    
    b6 = Me.Check27
    If b6 = -1 Then
        b6 = 6
    End If
    
    b7 = Me.Check345
    If b7 = -1 Then
        b7 = 7
    End If
    
    b = b1 & "," & b2 & "," & b3 & "," & b4 & "," & b5 & "," & b6 & "," & b7

I couldn’t use an option group because the user can select multiple boxes.
 
Just what are you trying to accomplish here??? Even if the code works.....let's say the user check b3 and b4 you will get the following for b: ,,3,4,,, and I don't think this is what you are looking for.....

Please give a little more detail as to what it is you are trying to accomplish and I will help you set up some code to check the check boxes and determine who is checked and who is not. If we knew what it was we were doing, it would not be called research, would it? - Albert Einstein [atom]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
I would like to have "b" = only the values that are selected.
So if the user selects b3 and b4 the result of "b" would =
b = 3,4

I don't know how to set "b" = to only the check boxes that are selected.


All these boxes belong to one question on a form.
 
Perhaps not the fastest or the cleanest way but here you go.....

'*****************Start Code********************
Dim bResult As String

bResult = ""

If Me![Check17] = -1 Then
If bResult = "" Then
bResult = 1
Else
bResult = bResult & ",1"
End If
End If
If Me![Check19] = -1 Then
If bResult = "" Then
bResult = 2
Else
bResult = bResult & ",2"
End If
End If
If Me![Check21] = -1 Then
If bResult = "" Then
bResult = 3
Else
bResult = bResult & ",3"
End If
End If
If Me![Check23] = -1 Then
If bResult = "" Then
bResult = 4
Else
bResult = bResult & ",4"
End If
End If
If Me![Check25] = -1 Then
If bResult = "" Then
bResult = 5
Else
bResult = bResult & ",5"
End If
End If
If Me![Check27] = -1 Then
If bResult = "" Then
bResult = 6
Else
bResult = bResult & ",6"
End If
End If
If Me![Check345] = -1 Then
If bResult = "" Then
bResult = 7
Else
bResult = bResult & ",7"
End If
End If

b = bResult
If we knew what it was we were doing, it would not be called research, would it? - Albert Einstein [atom]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Something close to the following. I did not generate a form w/ the check boxes, so it may be off in some small detail. If it were me, I would probably send the check boxes to the routine in a paramarray, and let the procedure figure out the how many ...



Code:
Public Function basChk2Str() As String

    'Michael Red    9/6/2002    Tek-Tips thread705-353483

    Dim chkAry(7) As Boolean
    Dim tmpStr As String

    chkAry(1) = (Me.Check17 <> 0)
    chkAry(2) = (Me.Check19 <> 0)
    chkAry(3) = (Me.Check21 <> 0)
    chkAry(4) = (Me.Check23 <> 0)
    chkAry(5) = (Me.Check25 <> 0)
    chkAry(6) = (Me.Check27 <> 0)
    chkAry(7) = (Me.Check345 <> 0)

    Idx = 1
    While Idx <= UBound(chkAry)
        
        If (chkAry(Idx) = True) Then
            If Len(tmpStr > 0) Then
                tmpStr = tmpStr & &quot;, &quot;
            End If
            tmpStr = tmpStr & &quot;b&quot; & Trim(Str(Idx))      ' & &quot;, &quot;
        End If
        Idx = Idx + 1
    Wend

    basChk2Str = tmpStr

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top