Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003
    Posts
    36

    Unanswered: Filtering a form

    I need to Form B based on info selected in Form A. After a user enters the selection criteria, they hit the 'ok' button. In the Click event of the 'ok' button, I do a

    If Nz(Forms("frmParameterEntry-Students").Controls("Zip"), 0) <> 0 Then
    If strWhere <> "" Then strWhere = strWhere & " And "
    strWhere = strWhere & "[Zip] Like " & Forms("frmParameterEntry-Students").Controls("Zip") & "*"
    End If

    DoCmd.OpenForm "frmStudents", , , strWhere, , acWindowNormal

    If when Form B is opened, it contains all the records, not just the filtered records. So, then I tried doing the filtering on the Form B itself. I went to the Filter property for the form and did the same logic with all sorts of variations for handling the strings (Zip is a text field)

    Zip Like "98*"
    "Zip Like '98*'"
    "tblStudents.Zip Like '98*'"

    etc.

    Same problem. All records returned. Am I missing something fundamental about filtering?

  2. #2
    Join Date
    May 2002
    Location
    London
    Posts
    87
    This was the approach I used:used to display a form with a filiter depending on the value selected in the main form:

    Code:
    Private Sub cmdDetail_Click()
    Application.Echo False
    DoCmd.OpenForm "frmBSDetail", acNormal
    Forms("frmBSDetail").Filter = "BSItem = " & BSItemID
    Forms("frmBSDetail").FilterOn = True
    Forms("frmBSDetail").Controls("lblTotal").Caption = "Total for BS " & BSItemName
    Application.Echo True
    End Sub

  3. #3
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    You can also solve this problem by setting the source code for the second form at something like this :
    SELECT * FROM tblA WHERE ZIP Like Forms.[frmParameterEntry-Students].[Zip] & '*'

  4. #4
    Join Date
    Apr 2003
    Posts
    36
    Basically, my forms aren't filtering, whether I filter in code or through the Filter Property of the form. AllowFilter is set to YES, but still no luck. Any ideas on why this might be?

  5. #5
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    Originally posted by cranconsult
    Basically, my forms aren't filtering, whether I filter in code or through the Filter Property of the form. AllowFilter is set to YES, but still no luck. Any ideas on why this might be?
    Real simple : if you set the filter on a form, it is automatically loaded but it is not applied. To see the effect of the filter, you must apply it, either by using the menucommand <Records><Apply Filter / Sort> or in code by setting the FilterOn property to True.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •