By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,220 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,220 IT Pros & Developers. It's quick & easy.

Filtering Forms

P: 10
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub FindDway_AfterUpdate()
  2. Dim strSQL As String
  3. If IsNull(Me.FindDway) Then
  4.     ' If the combo is Null, use the whole table as the RecordSource.
  5.     Me.RecordSource = "floods"
  6. Else
  7.     strSQL = "SELECT DISTINCTROW floods.* FROM floods " & _
  8.         "INNER JOIN drainageways ON " & _
  9.         "floods.floodid = drainageways.dwayid " & _
  10.         "WHERE drainageways.dwayid = " & Me.FindDway & ";"
  11.     Me.RecordSource = strSQL
  12. End If
  13. End Sub
  15. Private Sub FindMunicip_AfterUpdate()
  16. Dim strSQL As String
  17. If IsNull(Me.FindMunicip) Then
  18.     ' If the combo is Null, use the whole table as the RecordSource.
  19.     Me.RecordSource = "floods"
  20. Else
  21.     strSQL = "SELECT DISTINCTROW floods.* FROM floods " & _
  22.         "INNER JOIN municipalities ON " & _
  23.         "floods.floodid = municipalities.municipid " & _
  24.         "WHERE municipalities.municipid = " & Me.FindMunicip & ";"
  25.     Me.RecordSource = strSQL
  26. End If
  28. End Sub
Dec 28 '11 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 31,707
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.
Dec 28 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.