hello there.
I have the following code which runs well, but after i add a "if" condition, it went wrong with " end if wiithout block if error".
**************
Private Sub lookup_Click()
Dim i As Variant
Dim strWhere As String
strWhere = ""
If Not IsNull(Me.city) Then '-------I added an condition here
For Each i In Me!city.ItemsSelected
If strWhere <> "" Then
strWhere = strWhere & " OR "
End If
strWhere = strWhere & "[city]='" _
& Me![city].ItemData(i) & "'"
strWhere = strWhere & " AND "
End If '--------this is the place cannot go through, says "end if without block if"
If Not IsNull(Me.Text9) Then
strWhere = strWhere & "([age] >= " & Me.Text9 & ") AND "
End If
If Not IsNull(Me.Text11) Then
strWhere = strWhere & "([age] <= " & Me.Text11 & ") AND "
End If
If Len(strWhere) > 0 Then
strWhere = Left(strWhere, Len(strWhere) - 5)
End If
Next i
Debug.Print strWhere
Me.subform.Form.Filter = strWhere
Me.subform.Form.FilterOn = True
End Sub
***********************
could any people help me?
I have the following code which runs well, but after i add a "if" condition, it went wrong with " end if wiithout block if error".
**************
Private Sub lookup_Click()
Dim i As Variant
Dim strWhere As String
strWhere = ""
If Not IsNull(Me.city) Then '-------I added an condition here
For Each i In Me!city.ItemsSelected
If strWhere <> "" Then
strWhere = strWhere & " OR "
End If
strWhere = strWhere & "[city]='" _
& Me![city].ItemData(i) & "'"
strWhere = strWhere & " AND "
End If '--------this is the place cannot go through, says "end if without block if"
If Not IsNull(Me.Text9) Then
strWhere = strWhere & "([age] >= " & Me.Text9 & ") AND "
End If
If Not IsNull(Me.Text11) Then
strWhere = strWhere & "([age] <= " & Me.Text11 & ") AND "
End If
If Len(strWhere) > 0 Then
strWhere = Left(strWhere, Len(strWhere) - 5)
End If
Next i
Debug.Print strWhere
Me.subform.Form.Filter = strWhere
Me.subform.Form.FilterOn = True
End Sub
***********************
could any people help me?