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

Help with (Example Filtering on a Form).

P: 5
Hi,

I've tried using this following code but I keep getting the following error:

Runtime Error 2448
You can't assign a value to this object.

Do you know what the problem may be?





CHAPTER 5 - FORM MODULE

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub txtFindAccountCode_AfterUpdate()
  5.     Call CheckFilter
  6. End Sub
  7.  
  8. Private Sub txtFindCreationDate_AfterUpdate()
  9.     Me!txtFindCreationDate = IIf(IsDate(Me!txtFindCreationDate), _
  10.                                  Format(Me!txtFindCreationDate, "d mmm yyyy"), _
  11.                                  "")
  12.     Call CheckFilter
  13. End Sub
  14.  
  15. Private Sub cboFindAccountType_AfterUpdate()
  16.     Call CheckFilter
  17. End Sub
  18.  
  19. 'CheckFilter produces the new Filter depending on the values currently in
  20. 'txtFindAccountCode, txtFindCreationDate & cboFindAccountType.
  21. Private Sub CheckFilter()
  22.     Dim strFilter As String, strOldFilter As String
  23.  
  24.     strOldFilter = Me.Filter
  25.     'txtFindAccountCode - Text
  26.     If Me!txtFindAccountCode > "" Then _
  27.         strFilter = strFilter & _
  28.                     " AND ([AccountCode] Like '" & _
  29.                     Me!txtFindAccountCode & "*')"
  30.     'txtFindCreationDate - Date
  31.     If Me!txtFindCreationDate > "" Then _
  32.         strFilter = strFilter & _
  33.                     " AND ([CreationDate]=" & _
  34.                     Format(CDate(Me!txtFindCreationDate), _
  35.                            "\#m/d/yyyy\#") & ")"
  36.     'cboFindAccountType - Numeric
  37.     If Me!cboFindAccountType > "" Then _
  38.         strFilter = strFilter & _
  39.                     " AND ([AccountType]=" & _
  40.                     Me!cboFindAccountType & ")"
  41.     'Debug.Print ".Filter = '" & strOldFilter & "' - ";
  42.     'Debug.Print "strFilter = '" & strFilter & " '"
  43.     'Tidy up results and apply IF NECESSARY
  44.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  45.     If strFilter <> strOldFilter Then
  46.         Me.Filter = strFilter
  47.         Me.FilterOn = (strFilter > "")
  48.     End If
  49. End Sub
Sep 6 '07 #1
Share this Question
Share on Google+
10 Replies


NeoPa
Expert Mod 15k+
P: 31,602
In the article itself (Example Filtering on a Form) is not the place to start a discussion or a question so I've moved your post as a question to the Access Forum.

I will try to get to this sometime today to see if I can answer your question.
Sep 6 '07 #2

NeoPa
Expert Mod 15k+
P: 31,602
Having now looked at your question it seems you want me to debug your code without even letting me know where your error occurred. The error message helps - but without the line of code it appears in it doesn't mean much

Please provide the information I need so that I can try to help you.
Sep 6 '07 #3

P: 5
My apologies. The error occurs on Line 46

Me.Filter = strFilter

Having now looked at your question it seems you want me to debug your code without even letting me know where your error occurred. The error message helps - but without the line of code it appears in it doesn't mean much

Please provide the information I need so that I can try to help you.
Sep 6 '07 #4

NeoPa
Expert Mod 15k+
P: 31,602
I was being Naive - I thought you'd posted your code.
I will need the code you're using as well as the line number the error occurrs on. We'll get there I'm sure - I just need the question.

*Edit - You're using the original code directly?
Sep 6 '07 #5

P: 5
I was being Naive - I thought you'd posted your code.
I will need the code you're using as well as the line number the error occurrs on. We'll get there I'm sure - I just need the question.
Here's the code I used.....

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboFindTL_AfterUpdate()
  2.     Call CheckFilter
  3. End Sub
  4.  
  5. Private Sub cboFindSurname_AfterUpdate()
  6.     Call CheckFilter
  7. End Sub
  8.  
  9. Private Sub CheckFilter()
  10.     Dim strFilter As String, strOldFilter As String
  11.  
  12.      strOldFilter = Me.Filter
  13.  
  14.     If Me!cboFindSurname > "" Then _
  15.         strFilter = strFilter & _
  16.                    " AND ([Surname] Like '" & _
  17.                      Me!cboFindSurname & "*')"
  18.  
  19.  
  20.     If Me!cboFindTL > "" Then _
  21.         strFilter = strFilter & _
  22.                     " AND ([Team Leader]=" & _
  23.                     Me!cboFindTL & ")"
  24.  
  25.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  26.     If strFilter <> strOldFilter Then
  27.         Me.Filter = strFilter
  28.         Me.FilterOn = (strFilter > "")
  29.     End If
  30. End Sub
Sep 6 '07 #6

NeoPa
Expert Mod 15k+
P: 31,602
If you can confirm that the error occurred on line #27 then I can look at it in more detail.
Sep 6 '07 #7

P: 5
I'm getting the error on line 27
Me.Filter = strFilter




Here's the code I used.....

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboFindTL_AfterUpdate()
  2.     Call CheckFilter
  3. End Sub
  4.  
  5. Private Sub cboFindSurname_AfterUpdate()
  6.     Call CheckFilter
  7. End Sub
  8.  
  9. Private Sub CheckFilter()
  10.     Dim strFilter As String, strOldFilter As String
  11.  
  12.      strOldFilter = Me.Filter
  13.  
  14.     If Me!cboFindSurname > "" Then _
  15.         strFilter = strFilter & _
  16.                    " AND ([Surname] Like '" & _
  17.                      Me!cboFindSurname & "*')"
  18.  
  19.  
  20.     If Me!cboFindTL > "" Then _
  21.         strFilter = strFilter & _
  22.                     " AND ([Team Leader]=" & _
  23.                     Me!cboFindTL & ")"
  24.  
  25.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  26.     If strFilter <> strOldFilter Then
  27.         Me.Filter = strFilter
  28.         Me.FilterOn = (strFilter > "")
  29.     End If
  30. End Sub
Sep 6 '07 #8

P: 5
Hi,

When debugging if I hoover over the variable strFilter on line 26 I can see that it has an actual valid string. But on line 27 it just doesn't seem to want to assign that string to the form.filter property. Does this help at all?


I'm getting the error on line 27
Me.Filter = strFilter
Sep 6 '07 #9

NeoPa
Expert Mod 15k+
P: 31,602
What type of field is [Team Leader]?
Is Me!cboFindTL of the same type?
Sep 6 '07 #10

NeoPa
Expert Mod 15k+
P: 31,602
Hi,

When debugging if I hoover over the variable strFilter on line 26 I can see that it has an actual valid string. But on line 27 it just doesn't seem to want to assign that string to the form.filter property. Does this help at all?
That does help and confirms my fear that this is not a code issue as much as a design issue. I can't imagine why this might happen I'm afraid.

Have you downloaded the example DB and seen if that works on your system?

PS. Ignore questions in earlier post as this info takes us past there.
Sep 6 '07 #11

Post your reply

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