473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

My form isn't filtering

Seth Schrock
2,965 Expert 2GB
I'm attempting to filter a subform based on a user ID, but no filter is taking place. I get no errors (run-time or compiler), but nothing happens. I don't work with filters much so I would assume that I'm doing something wrong, but I can't find it.

Here is the query that is the recordsource for the subform:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblLoans.LoanID
  2. , tblLoans.LoanNumber
  3. , tblLoans.Borrower
  4. , tblAppraisals.DateOrdered
  5. , tblAppraisals.DateReceived
  6. , tblLoans.Processor
  7. , tblLoans.LoanOfficer
  8. FROM tblAppraisals 
  9. INNER JOIN tblLoans ON tblAppraisals.LoanID = tblLoans.LoanID
  10. WHERE (((IsNull([CompletedDate]))<>False));
The Processor and LoanOfficer fields are what I'm trying to filter. However, the form doesnt' contain these fields. I didn't think that it needed to, but I could be wrong.

Here is my code to filter the form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. On Error GoTo Form_Error
  3.  
  4. Dim strFilter As String
  5.  
  6.  
  7. Call GetUserID
  8.  
  9. If IsNull(Application.TempVars("UserID").Value) Then
  10.     Call LockSystem
  11.     Exit Sub
  12. End If
  13.  
  14. Select Case Application.TempVars("UserType").Value
  15.     Case 1 'Loan Operations
  16.     'No filter
  17.     Me.cmdAdministrativeForms.Visible = True
  18.     Me.cmdAddressSearch.Visible = True
  19.  
  20.     strFilter = ""
  21.  
  22.     Case 2 'Loan Processor
  23.     Me.cmdAdministrativeForms.Visible = False
  24.     Me.cmdAddressSearch.Visible = False
  25.  
  26.     strFilter = "Processor = " & Application.TempVars("UserID").Value
  27.  
  28.     Case 3 'Loan Officer
  29.     Me.cmdAdministrativeForms.Visible = False
  30.     Me.cmdAddressSearch.Visible = False
  31.  
  32.     strFilter = "LoanOfficer = " & Application.TempVars("UserID").Value
  33.  
  34.     Case 4 'Administrator
  35.     'No filter
  36.     Me.cmdAdministrativeForms.Visible = True
  37.     Me.cmdAddressSearch.Visible = True
  38.  
  39.     strFilter = ""
  40.  
  41. End Select
  42. Me.sfrmAppraisalsSummary.Form.FilterOn = True
  43. Me.sfrmAppraisalsSummary.Form.Filter = strFilter
  44.  
  45. Me.sfrmCentralizedProcessingSummary.Form.FilterOn = True
  46. Me.sfrmCentralizedProcessingSummary.Form.Filter = strFilter
  47.  
  48. Me.sfrmMortgageLogSummary.Form.FilterOn = True
  49. Me.sfrmMortgageLogSummary.Form.Filter = strFilter
  50.  
  51.  
  52. 'MsgBox "User ID: " & Application.TempVars("UserID").Value & vbCrLf & _
  53.        "User Type: " & Application.TempVars("UserType").Value
  54.  
  55.  
  56.  
  57. Form_Exit:
  58.     Exit Sub
  59.  
  60.  
  61. Form_Error:
  62.     MsgBox "Error Description: " & Err.Description & vbCrLf & _
  63.            "Number: " & Err.Number & vbCrLf
  64.  
  65.     Resume Form_Exit
  66.  
  67.  
  68. End Sub
I know my TempVars are working properly, because the buttons are correctly being visible or invisiable. My problem is that when I have a loan processor log on (case 2), I can still see all the records. I haven't tried a loan officer yet, but I would assume that since the code is the same, I will get the same result.
Jan 16 '13 #1

✓ answered by NeoPa

Ah. In that case just switch the two property settings around, but don't always set .FilterOn to True. If there's no filter then it doesn't make good sense. Try :
Expand|Select|Wrap|Line Numbers
  1. Me.sfrmAppraisalsSummary.Form.Filter = strFilter
  2. Me.sfrmAppraisalsSummary.Form.FilterOn = (strFilter > "")
  3.  
  4. Me.sfrmCentralizedProcessingSummary.Form.Filter = strFilter
  5. Me.sfrmCentralizedProcessingSummary.Form.FilterOn = (strFilter > "")
  6.  
  7. Me.sfrmMortgageLogSummary.Form.Filter = strFilter
  8. Me.sfrmMortgageLogSummary.Form.FilterOn = (strFilter > "")

11 2296
Rabbit
12,516 Expert Mod 8TB
Are those fields string values? Because if they are you need to surround the values in quotes.
Jan 16 '13 #2
Seth Schrock
2,965 Expert 2GB
The table is storing them as numbers. However in the table I have them with a combo box lookup from a different table so the visible value is a string. I'm attempting to filter based in the numerical value as I believe that is the correct way to do it.

Also, if my filter was wrong, wouldn't it filter out all of the records instead of showing them all?
Jan 16 '13 #3
Rabbit
12,516 Expert Mod 8TB
I don't know if this is the issue but try flipping the order of setting the filter and turning the filter on.
Jan 16 '13 #4
zmbd
5,501 Expert Mod 4TB
Rabbit more than likely has it for you!

Another thing I've had to do when changing a filter is to "refresh" the form (subform). You don't need a "requery" as you're simply filtering.
Jan 16 '13 #5
Seth Schrock
2,965 Expert 2GB
I will try both your ideas when I get to work tomorrow. I have seen the both ways online with the filter being set before turning it on and also after turning it on, but I will give it a shot. The refresh also seems likely.
Jan 16 '13 #6
NeoPa
32,556 Expert Mod 16PB
The only value your code is trying to filter by is the UserID. From your other questions I'm guessing this is the Windows User ID - which is a text field. The filter string you are using is treating it as a numeric literal rather than a text one. You need something like (although I suspect the Application. part is redundant) :
Expand|Select|Wrap|Line Numbers
  1. strFilter = "[LoanOfficer] = '" & Application.TempVars("UserID") & "'"
See Quotes (') and Double-Quotes (") - Where and When to use them.

It also makes better sense to turn the filter on only after it has a value set (As Rabbit suggested).
Jan 17 '13 #7
Seth Schrock
2,965 Expert 2GB
I actually have a table that lists the users that are allowed in my database. I use the windows user name to get the primary key for that employee (UserID). All of the loans (the records that I'm filtering) have a loan officer and a loan processor assigned to it. Part of the employee table is an Employee Type, hence the UserType TempVar. If the user is a Loan Processor, then I filter based on the Processor field. If the user is a Loan Officer, I filter based on the LoanOfficer field. Both of these fields are tied to the Employee table's EmployeeID field, thus I need number fields not strings. But you are correct in tying my other questions in with this one as this is all part of the same project.
Jan 17 '13 #8
NeoPa
32,556 Expert Mod 16PB
Ah. In that case just switch the two property settings around, but don't always set .FilterOn to True. If there's no filter then it doesn't make good sense. Try :
Expand|Select|Wrap|Line Numbers
  1. Me.sfrmAppraisalsSummary.Form.Filter = strFilter
  2. Me.sfrmAppraisalsSummary.Form.FilterOn = (strFilter > "")
  3.  
  4. Me.sfrmCentralizedProcessingSummary.Form.Filter = strFilter
  5. Me.sfrmCentralizedProcessingSummary.Form.FilterOn = (strFilter > "")
  6.  
  7. Me.sfrmMortgageLogSummary.Form.Filter = strFilter
  8. Me.sfrmMortgageLogSummary.Form.FilterOn = (strFilter > "")
Jan 17 '13 #9
Seth Schrock
2,965 Expert 2GB
Well I certainly feel better that I wasn't too far off with my attempt. I will give this a try tomorrow and will let you know the results.
Jan 17 '13 #10
Seth Schrock
2,965 Expert 2GB
That did it. Thanks everyone. I also used your solution of only turning on the filter if necessary, which makes perfect sense.
Jan 17 '13 #11
NeoPa
32,556 Expert Mod 16PB
8-) Thanks for the update.

It does more than just that though Seth. It also turns it off (Not in this situation of course, but in code that gets run more than once.) after it's been used before, but is not required on this particular iteration.
Jan 17 '13 #12

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
1
by: mstery | last post by:
I have a report generated via an ID selection made in a dropdown on a form. The report filters by an on click event in a preview report button on the form. Everything in the report, including...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
12
by: Claude | last post by:
Hi, I've designed my own form checking code for name, address, email, comment box etc. What my client keeps getting in his consumer feedback forms is "spam" from companies who repeatedly...
19
by: Chantelle | last post by:
I've got this A2K DB that has a continuous form that lists Suppliers and their details. The form has a field for each supplier that holds several Keywords that reflect the suppliers products or...
4
by: dizzydangler | last post by:
Hi all, I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in...
3
NeoPa
by: NeoPa | last post by:
Cascaded Form Filtering CHAPTER 1 - TABLE OF CONTENTS (Including attached database) CHAPTER 2 - INTRODUCTION CHAPTER 3 - TABLE LAYOUT CHAPTER 4 - FORM LAYOUT CHAPTER 5 - FORM MODULE CHAPTER 6...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.