Need help to understand code

SyafiqIzzat

Registered User.
Local time
Today, 15:05
Joined
Aug 16, 2010
Messages
19
Hello all, I'm working with filtering data and I had just found this code, very helpful indeed but I just need help to understand it in depth.

Dim strSQL As String

strSQL = "1 = 1"

If Len(Nz(Me.Combo104, "")) > 0 Then
strSQL = strSQL & " and [Part Type] = """ & Me.Combo104 & """"
End If
If Len(Nz(Me.Combo110, "")) > 0 Then
strSQL = strSQL & " and [Identifier] = """ & Me.Combo110 & """"
End If
If Len(Nz(Me.Combo113, "")) > 0 Then
strSQL = strSQL & " and [Shaft] = """ & Me.Combo113 & """"
End If
Me.Filter = strSQL
Me.FilterOn = True

I don't understand what does strSQL ="1 = 1" means? and what actually the rest of the codes do from strSQL="1 = 1".

Thank You in advance
 
1=1 is a condition that will always be true. Basically it just gives you something to start with so that any following conditions can use " AND ...". Without that, you'd have to test to see if the string had a value already or not.

Each succeeding If/Then block will add to that string if a selection has been made in a combo.
 

Users who are viewing this thread

Back
Top Bottom