If.. AND If.. Then coding question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use a form with check boxes. I currently have code that If one box is
checked
Then change a list to "1"

Private Sub XXX_AfterUpdate()
If (Me.XXX = -1) Then
Me.List117 = "1"
End If


I want to write a code that if two (or more) boxes are checked Then
change list to 2

I tried this but it didn't work
Private Sub XXX_AfterUpdate()
If (Me.XXX = -1) and
If (If Me.YYY = -1 ) Then
Me.List117 = "2"
End If


I would appreciate any help.
 
It would be

If Me.XXX = -1 and Me.YYY = -1 Then
Me.List117 = "2"
End If

But why do you need to do that?
You can always get that resault using a query

Select TableName.*, IIf([XXX]=True And [YYY]=True,1,0) From TableName
 
I think this is what you want
If (Me.XXX = -1) and (Me.YYY = -1 ) Then
Me.List117 = "2"
End If

or more simply
If Me.XXX and If Me.YYY Then
Me.List117 = "2"
End If

hth,
James Deckert
 
Try this

Private Sub XXX_AfterUpdate()
If Me.XXX = -1 and Me.YYY = -1 Then
Me.List117 = "2"
End If

hth
 
You stated that there may be two or more checkboxes. If so, your if-then
statement could get out of hand, so instead check out help for the "for
each" statement, like this:

Dim ctl As Variant
Dim frm As Form
Set frm = Forms.YourformName
Dim ct As Integer
For Each ctl In frm
If (TypeOf ctl Is CheckBox) Then
If ctl.Value = -1 Then
ct = ct + 1
End If
End If
Next
If ct > 1 Then
Me.List117 = "2"
Else
Me.List117 = "1"
End If

Damon
 
Back
Top