Search form (1 Viewer)

Falcon88

Registered User.
Local time
Today, 17:39
Joined
Nov 4, 2014
Messages
306
hii all dears

based on this example i build a seperated filter form (without record source data) , to filter another form , but it does not filter that another form .
i use this code :

Code:
Dim strWhere As String                  'The criteria string.
    Dim lngLen As Long                      'Length of the criteria string to append to.
    Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.

      'Number field example. Do not add the extra quotes.
    If Not IsNull(Me.CVZ) Then
        strWhere = strWhere & "(Forms![MainFrm]![InsurCmpName] = " & Me.CVZ & ") AND "
    End If
     If Not IsNull(Me.DateXz) Then
        strWhere = strWhere & "(format(Forms![MainFrm]![OrderDate],'m') = " & Me.DateXz & ") AND "
    End If
    'ByDatSearch
    If Not IsNull(Me.ByDatSearch) Then
        strWhere = strWhere & "(Forms![MainFrm]![OrderID] = " & Me.ByDatSearch & ") AND "
    End If
    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then     'Nah: there was nothing in the string.
        MsgBox "No criteria", vbInformation, "Nothing to do."
    Else                    'Yep: there is something there, so remove the " AND " at the end.
        strWhere = Left$(strWhere, lngLen)
        'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
        'Debug.Print strWhere
        
        'Finally, apply the string as the form's Filter.
        Forms![MainFrm].Filter = strWhere
        Forms![MainFrm].FilterOn = True
        Forms![MainFrm].OrderBy = "[OrderID] ASC"
        Forms![MainFrm].OrderByOn = True
    End If
 
You don't need the Forms![MainForm]! in the strWhere construction; note that you need to wrap text (strings) in single quotes (or double doublequotes "") and dates with #. So if InsCompName is an alpha string you would have strWhere = strWhere & "([InsurCmpName] ='" & Me.CVZ & "') AND " and so on. For numeric values you leave them like you have them.

Cheers,
 
this function makes wrapping the delimiters much easier. CSQL
Code:
strWhere = strWhere & "([InsurCmpName] =" & csql(Me.CVZ) & ") AND "
 
You don't need the Forms![MainForm]! in the strWhere construction; note that you need to wrap text (strings) in single quotes (or double doublequotes "") and dates with #. So if InsCompName is an alpha string you would have strWhere = strWhere & "([InsurCmpName] ='" & Me.CVZ & "') AND " and so on. For numeric values you leave them like you have them.

Cheers,
thanks , dear plz note : i use filter form (frmFilter , it's record source="") to filter data on MainFrm that is another seperated form
 
It doesn't matter if it is a different form, the passed strWhere variable would contain the controls on that form so no need to fully qualify them by adding the Forms![MainForm]. But the problem is probably not that but improper wrapping of the individual variables....

Cheers,
 

Users who are viewing this thread

Back
Top Bottom