Private Sub Command1_Click()
Dim zSearch As String
If Trim(Text1.Text) = "" Then GoTo sendbad101:
If Trim$(Text1.Text) <> "" Then zSearch = "[Prenom] LIKE '" & Trim$(Text1.Text) & "%'"
If Trim$(Text2.Text) <> "" Then
If Trim$(zSearch) <> "" Then
zSearch = zSearch & " And [Mere] LIKE '" & Trim$(Text2.Text) & "%'"
Else
zSearch = "[Mere] LIKE '" & Trim$(Text2.Text) & "%'"
End If
End If
If Trim$(Text3.Text) <> "" Then
If Trim$(zSearch) <> "" Then
zSearch = zSearch & " And [Groupage] LIKE '" & Trim$(Text3.Text) & "%'"
Else
zSearch = "[Groupage] LIKE '" & Trim$(Text3.Text) & "%'"
End If
End If
If Trim$(Text4.Text) <> "" Then
If Trim$(zSearch) <> "" Then
zSearch = zSearch & " And [Rhesis] LIKE '" & Trim$(Text4.Text) & "%'"
Else
zSearch = "[Rhesis] LIKE '" & Trim$(Text4.Text) & "%'"
End If
End If
If Trim$(Text5.Text) <> "" Then
If Trim$(zSearch) <> "" Then
zSearch = zSearch & " And [Grandpere] LIKE '" & Trim$(Text5.Text) & "%'"
Else
zSearch = "[Grandpere] LIKE '" & Trim$(Text5.Text) & "%'"
End If
End If
If Trim$(zSearch) = "" Then Set MSHFlexGrid1.DataSource = Nothing: Exit Sub
If RS.State = 1 Then RS.Close
RS.CursorLocation = adUseClient
RS.Open "Select * From TB1 Where " & zSearch, DB, adOpenStatic, adLockPessimistic
If RS.RecordCount > 0 Then
Set MSHFlexGrid1.DataSource = RS.Clone
Else
Set MSHFlexGrid1.DataSource = Nothing
End If
DrawFlex
Exit Sub
sendbad101:
If RS.State = 1 Then RS.Close
RS.CursorLocation = adUseClient
'RS.Open "Select * From TB1 Where " & zSearch, DB, adOpenStatic, adLockPessimistic
RS.Open "Select * From TB1 Order By [Code] ASC", DB, adOpenStatic, adLockPessimistic
If RS.RecordCount > 0 Then
Set MSHFlexGrid1.DataSource = RS.Clone
Else
Set MSHFlexGrid1.DataSource = Nothing
End If
DrawFlex
End Sub