Results 1 to 9 of 9

Thread: Access vba form filter question

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    33

    Access vba form filter question

    Hello,

    I am working on an Access app that has a button on a form which changes the contents of a subform and applies a filter to the form in the subform. This all works fine, but the problem I have is that the filter sometimes takes a couple of seconds to complete. I would like to be able to change the cursor to hourglass while the filter is running and then change it back to normal once the filter has completed. Any ideas on which event to use?

    By the way, I'm using Access 2003. Here is the code I'm currently using to open the form:

    VB Code:
    1. If (cbxNav.Value <> "Please select a destination") Then
    2.    
    3.         If (cbxNav.Value = "Management") Then
    4.             Forms("frmMain").Controls("sbfrmContent").SourceObject = "frmManagement"
    5.         Else
    6.             DoCmd.Hourglass True
    7.             Forms("frmMain").Controls("sbfrmContent").SourceObject = "frmDaily"
    8.             Forms("frmMain").Controls("sbfrmContent").Form.Filter = "Status = '" & cbxNav.Value & "'"
    9.             Forms("frmMain").Controls("sbfrmContent").Form.FilterOn = True
    10.             DoCmd.Hourglass False  'this happens too soon
    11.         End If
    12.     End If

    Thanks,
    Ranthalion

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access vba form filter question

    Try it in your subforms Form_Load or in the procedure where your main form is changing its content on with, like a command button click or a record navigation change event like Form_Current.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    33

    Re: Access vba form filter question

    Thanks for the recommendations. I've tried OnLoad and OnCurrent, but the events fire before the filter is finished, causing the cursor to change back to normal before I want it to...

    I want the cursor to stay hourglass until the record navigation section shows how many records are in the recordset.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access vba form filter question

    Those events from the subform or parent form?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    33

    Re: Access vba form filter question

    Sorry, those are the events on the subform.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access vba form filter question

    Try it in the parent form as its the one initiating the filter.

    Also, try the Form_Filter and possibly the Form_AfterUpdate events.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    33

    Re: Access vba form filter question

    Thanks for your help. I just gave that a shot... No dice.

    I tried just making a function and calling it during each event that fires on the parent form and on the sub form, but it doesn't seem that any event fires when the filter is finished and the navigation control is finished updating...

    The apply filter and on filter events fire when I right click a field and filter on it from the subform, but not when I apply the filter through code...

    The current work around I'm using now is to have a timer event on the subform that fires after 1.5 seconds, which changes the mouse pointer and disables the timer...

    Let me know if you have any other ideas.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access vba form filter question

    Why not code a macro to do it and then in your form you can call the macro and it can change the mouse, apply the filter, and then change the mouse back? May be a more synchronous operation.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    33

    Re: Access vba form filter question

    Good idea, but that one didn't work either. It seems that the filter is applied and completed, but the record navigation control takes a longer time to complete than the filter takes to complete. So, the data in my form changes, but the navigation control takes a little longer to calculate the total number of records and no event is raised from that control...

    I suppose I could make my own navigation controls, but that just doesn't really seem worth it for this project...

    Thanks again!

Posting Permissions

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



Click Here to Expand Forum to Full Width