Filtering Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rwest
    New Member
    • Dec 2011
    • 10

    Filtering Forms

    I have a form connected to a table called floods. On this form I want to filter the records by date, municipality, and drainageway.the date comes from the floods table but the municipality and the drainageway are both subforms connected to the tables municipalities and drainageways respectively.I have tried to come up with the codes for these filters but nothings is working right.part of my code is below. Any help with this would be greatly appreciated. Thanks!

    I made a text box for the filter date named Find Date and 2 combo boxes for the municipality and drainageway maned Find Minucip and Find Dway.
    Code:
    Private Sub FindDway_AfterUpdate()
    Dim strSQL As String
    If IsNull(Me.FindDway) Then
        ' If the combo is Null, use the whole table as the RecordSource.
        Me.RecordSource = "floods"
    Else
        strSQL = "SELECT DISTINCTROW floods.* FROM floods " & _
            "INNER JOIN drainageways ON " & _
            "floods.floodid = drainageways.dwayid " & _
            "WHERE drainageways.dwayid = " & Me.FindDway & ";"
        Me.RecordSource = strSQL
    End If
    End Sub
    
    Private Sub FindMunicip_AfterUpdate()
    Dim strSQL As String
    If IsNull(Me.FindMunicip) Then
        ' If the combo is Null, use the whole table as the RecordSource.
        Me.RecordSource = "floods"
    Else
        strSQL = "SELECT DISTINCTROW floods.* FROM floods " & _
            "INNER JOIN municipalities ON " & _
            "floods.floodid = municipalities.municipid " & _
            "WHERE municipalities.municipid = " & Me.FindMunicip & ";"
        Me.RecordSource = strSQL
    End If
    
    End Sub
    Last edited by NeoPa; Dec 28 '11, 10:53 PM. Reason: Added mandatory [CODE] tags for you
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    You may find Example Filtering on a Form helpful for your problem.

    PS. Please try to remember to post your questions properly. Questions live in the Answers forum and not the Insights one. They also need [ CODE ] tags if code is included (See When Posting (VBA or SQL) Code and especially [CODE] Tags Must be Used).

    I have moved and fixed this one, but would rather not have to do so for your questions in future.
    Last edited by NeoPa; Dec 28 '11, 10:55 PM.

    Comment

    Working...