Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I have a from with the following code in the 'On Apply Filter' event:

    If ApplyType = acApplyFilter Then
    If DCount("*", "tblRentalValuations", Me.Filter) = 0 Then
    msgbox "No records were found!", vbExclamation
    Me.Filter = ""
    End If
    End If

    On all other forms where this code is sued, it is fine and returns a message box.

    On two particular forms it causes access to hang and you then have to shut it down by task manager.

    Any ideas?
    Best Regards,

    Luke

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,435
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    From the information supplied my guess is that since you clear the filter in an ApplyFilter event you are re-triggering that event causing an endless loop. This assumes that the filters applied by all the forms are the same where it works correctly and different where it doesn't.

    Can you break {Ctrl+Break} into the code when the machine hangs and go into debug mode and use the immediate window to see what values are being returned?

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RetiredGeek View Post
    From the information supplied my guess is that since you clear the filter in an ApplyFilter event you are re-triggering that event causing an endless loop. This assumes that the filters applied by all the forms are the same where it works correctly and different where it doesn't.

    Can you break {Ctrl+Break} into the code when the machine hangs and go into debug mode and use the immediate window to see what values are being returned?

    RG
    No it won't break into where it hangs, my pressing Ctrl and 'Break'.
    Best Regards,

    Luke

  4. #4
    Star Lounger
    Join Date
    Dec 2009
    Location
    Bellevue, WA
    Posts
    61
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Try the code me.filteron = false instead of clearing the filter.

    If you can't break with control-break, then put in a breakpoint and step through to see what is being done.

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    The Apply Filter event has a Cancel argument.

    If you set Cancel = true, that Cancels the application of the filter.
    Regards
    John



  6. #6
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Forgot to mention that it only does it when it cannot find any results (i.e returning no records found)
    Best Regards,

    Luke

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    What happens if you try using Cancel = true ?

    Code:
    If ApplyType = acApplyFilter Then
     If DCount("*", "tblRentalValuations", Me.Filter) = 0 Then
    msgbox "No records were found!", vbExclamation
     Cancel = true
    End If
     End If
    Regards
    John



  8. #8
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It still hangs and you have to end the msaccess.exe process.
    Best Regards,

    Luke

  9. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,435
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by Lstclair55 View Post
    Forgot to mention that it only does it when it cannot find any results (i.e returning no records found)
    Give this a try:

    Code:
    Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
    
      If ApplyType = acApplyFilter Then
        If IsNull(Me.Filter) Then
          msgbox "No records were found!", vbExclamation
          Cancel = true
        End If
      End If
    
    End Sub      'Form_ApplyFilter()
    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  10. #10
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I don't know why it is hanging, but I have another suggestion.

    Instead of performing the check in the Apply Filter event, put the count code in the event that tries to set the filter.
    Then only apply the filter if the count is > 0.

    I don't know why that should be any better, but I do it that way without problem.

    Added a bit later:
    Further investigation makes me think this is not a helpful suggestion. I always apply filters via code.
    The Applyfilter event does not occur when you set a filter using code. So you must set the filter using the built-in filtering, rather than code.
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •