Private Sub Command3_Click()
Dim K As String
Set r1 = Nothing
K = "select format(eff,""dd/mm/yyyy"") as Effective,wellnum,choke,I AS Netoil,bsw as WC,gor as GOR,fluid,SALI AS SALINITY,REM"
K = K & " from qwell where wellnum<>'" & g2321 & "'"
If Text2 <> "" Then K = K & " and wellnum='" & Text2 & "'"
If Combo7 <> "" Then K = K & " and station='" & Combo7 & "'"
If Combo1 <> "" Then K = K & " and REM='" & Combo1 & "'"
If IsNumeric(Text4) Then K = K & " and gor>=" & Text4
If IsDate(MaskEdBox1) Then K = K & " and eff=#" & Format(MaskEdBox1, "mm/dd/yyyy") & "#"
If IsDate(MaskEdBox3) Then K = K & " and eff>=#" & Format(MaskEdBox3, "mm/dd/yyyy") & "#"
If IsDate(MaskEdBox2) Then K = K & " and eff<=#" & Format(MaskEdBox2, "mm/dd/yyyy") & "#"
If r1.State = 1 Then r1.Close
r1.Open K, cn, adOpenKeyset, adLockPessimistic
Set MSHFlexGrid1.DataSource = r1.DataSource
Lab16.Caption = r1.RecordCount
End Sub