Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2006
    Posts
    37

    Unanswered: Refresh & requery

    Ok going to try to give a quick background on why I need this...

    I have a form that is going to feed some VBA code and queries to limit the data that the calculations are taking place on.

    The form has four list boxes on it with multiple selections allowed. The data chosen in the first list box feeds VBA code that creates the query that is the RowSource for the second list box and so on. I wrot ethe VBA code to handle any number of selections in the list boxes. I have also set up the event procedures to rerun the code and requery the queries.

    The problem comes in that this still does not update the data in the listboxes on screen. From doing some more reading in my VBA book I have found out that what I need to do is refresh the form / listboxes. The only way my VBA book tells me how to do this is by hitting the F9 key. I would really prefer to aviod having my user do this after each selection.

    Does anyone know of a way I can programattically refresh or simulate the F9 keystroke?

    Thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    To refresh your Form:

    Me.Refresh
    or
    Forms("myFormName").Refresh
    --------------------------------

    To Requery your Form:

    Me.Requery
    or
    Forms("myFormName").Requery
    --------------------------------

    To Requery your ListBox:

    Me.myListBoxName.Requery
    or
    Forms("myFormName").myListBoxName.Requery

    There is no Refresh statement for the ListBox.

    .
    Last edited by CyberLynx; 07-30-06 at 02:56.
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Refresh

    I've also at times just set the rowsource (i.e. me.MyListBox.rowsource = "MyQuery" or a sql statement.) This has worked well when I leave the rowsource of the listbox blank until someone hits a search button (then it doesn't load when the form loads and the form will load a lot quicker). But again, I'm not quite sure the trade-offs in resources used.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Feb 2006
    Posts
    37
    Thanks for the help guys.

    I had a feeling it would be that simple but I just hadn't found any references to a refresh command.

    I simply added Forms!"MyFormName".Refresh into the VBA code that is called in my AfterUpdate Event. I use a requery command and then the refresh command and things are working beautifully.

    Thank you so much... thats why I love this forum.

  5. #5
    Join Date
    Jul 2008
    Posts
    1

    Simulate {F9} in MS Access 2000 VB code

    I was able to simulate {F9} in MS Access 2000 VB code using a 'sendkeys' statement.

    Dim str As String
    str = "{f9}"
    SendKeys str, True

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I personally try to avoid using the Sendkeys command. Not to say I haven't used it, I would just opt though to use a refresh or requery command if that works. I usually use the sendkeys command as a last option only because I don't like programmatically sending keystrokes to the form (as this can sometimes lead to conflicts with other software running.)
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Yup, I dodge SendKeys entirely. Imagine Access 2009 that doesn't support the same keystrokes. F9 now means spell check or something stupid like that. Any code using SendKeys would need re-writing.

    No thanks!

    Me.Refresh is much more readable as well.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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