My Assistant
![]() ![]() |
|
|
Sep 24 2004, 10:32 AM
Post
#1
|
|
|
UtterAccess Guru Posts: 513 From: Annapolis, MD USA |
I'm incuding this code because it workes & it's easy to understand!
5 combo boxes are used to define a query. Any all or none can requery the form. You could easily have more or less combo boxes. John Orlando - Enjoy! CODE Private Sub cmdApplyFilter_Click()
Dim stFilter As String Dim stLien As String Dim stStatus As String Dim stLevel2 As String Dim stBranch As String Dim stInvestor As String 'This Code developed by John C. Orlando 'UtterAccess.com member jcorlando On Error GoTo HandleError DoCmd.ShowAllRecords 'First I convert any Nulls to Strings of "" in the variables '-------------------------------------------------------------------------------- stLien = Nz(Me.cboFilterLienPos, "") stStatus = Nz(Me.cboFilterRepurchStatus, "") stLevel2 = Nz(Me.cboFilterLevel2, "") stBranch = Nz(Me.cboFilterBranch, "") stInvestor = Nz(Me.cboFilterInvestor, "") 'If the variables are not "" then I define the variable as that 'portion of the WHERE statement containing the field and the variables. '----------------------------------------------------------------------------------- If stLien <> "" Then stLien = "[intLienPos] = " & stLien & " " If stStatus <> "" Then stStatus = " [chrRepurchStatus] = '" & stStatus & "' " If stLevel2 <> "" Then stLevel2 = " [chrChargeOffLevel2] = '" & stLevel2 & "' " If stBranch <> "" Then stBranch = " [chrBranch] = '" & stBranch & "' " ' This is the Cost Center If stInvestor <> "" Then stInvestor = " [chrInvestor] = '" & stInvestor & "' " 'Now I apply the filters if all or none are populated. '---------------------------------------------------------------------------------- If stLien = "" And stStatus = "" And stLevel2 = "" And stBranch = "" And stInvestor = "" Then DoCmd.ShowAllRecords Me.Requery GoTo EndCode End If If stLien <> "" And stStatus <> "" And stLevel2 <> "" And stBranch <> "" And stInvestor <> "" Then stFilter = stLien & " AND " & stStatus & " AND " & stLevel2 & " AND " & stBranch & " AND " & stInvestor DoCmd.ApplyFilter , stFilter DoCmd.Requery GoTo EndCode End If 'Since the above 2 conditions were not meet, 'the var - stFilter must be edited as follows: 'the applied as the filter '---------------------------------------------------------------------------------------- stFilter = stLien & " AND " & stStatus & " AND " & stLevel2 & " AND " & stBranch & " AND " & stInvestor stFilter = Replace(stFilter, " AND AND ", " AND ", , , vbTextCompare) stFilter = Replace(stFilter, " AND AND ", " AND ", , , vbTextCompare) stFilter = Replace(stFilter, " AND AND ", " AND ", , , vbTextCompare) If Left(stFilter, 5) = " AND " Then stFilter = Mid(stFilter, 6) If Right(stFilter, 5) = " AND " Then stFilter = Left(stFilter, Len(stFilter) - 5) stFilter = Trim(stFilter) 'Used to test the above sequence 'MsgBox stFilter & "|", vbOKOnly DoCmd.ApplyFilter , stFilter DoCmd.Requery GoTo EndCode EndCode: Exit Sub HandleError: If Err.Number <> 2501 And Err.Number <> 0 Then MsgBox Err.Number & " " & Err.Description Else: Err.Clear End If Resume EndCode End Sub |
|
|
|
Dec 11 2012, 03:13 PM
Post
#2
|
|
|
UtterAccess Member Posts: 24 |
[quote name='jcorlando' date='Sep 24 2004, 07:32 AM' post='546910']
5 combo boxes are used to define a query. Any all or none can requery the form. You could easily have more or less combo boxes. Dim stFilter As String Dim stLien As String Dim stStatus As String Dim stLevel2 As String Dim stBranch As String Dim stInvestor As String Just trying to understand what you have here as I am new to Access and in using the code to get what i want. Each of those lines are combo boxes? So Filter is a combo box, lien is a combo box, Status is a combo box etc.? |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 01:56 PM |