Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2008
    Posts
    59

    Unanswered: How to requery my listbox

    I have a listbox which I need to requery when my page opens. I have tried many different ways of doing this but all without luck.

    The listbox is based on a page/tab of a form. It is on a tab which doesn't load up when the form first opens. The user has to click the tab before it loads.

    I've tried doing various things, such as trying to SetFocus on the listbox when the tab opens and then having the listbox requery when focussed, but no luck. I've tried OnEnter and OnLoad but I need it to requery as soon as the tab is opened rather than when the box is clicked.

    What is the best way of doing this?

    Thanks
    Russ

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I would do this in the Form_Open event procedure. If it has to be when you click a tab, then I would do it when the first control on the tab's tab order gets the focus.
    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

  3. #3
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    You could also do it when your listbox gets the focus as per the following code. Change Listbox to the name of your listbox.

    Private Sub listbox_GotFocus()
    DoCmd.Requery "listbox"
    End Sub

  4. #4
    Join Date
    Nov 2008
    Posts
    59
    Hey, thanks for the help, but I have actually tried both of these suggestions but without any luck. The OnLoad function doesn't seem to make any difference and the GotFocus only works when you click inside the Listbox but I need it to load up automatically.

    My Listbox is called 'SurveyList'. These are some of the solutions I've tried but without any luck. Does anyone have any other suggestions?

    Private Sub SurveyList_Enter()
    Me.SurveyList.Requery
    End Sub

    Private Sub SurveyList_GotFocus()
    Me.SurveyList.Requery
    End Sub

    Private Sub TabCtl75_Click()
    Me.SurveyList.SetFocus
    End Sub

    Private Sub Form_Load()
    Me.SurveyList.Requery
    End Sub

    Private Sub Form_Open(Cancel As Integer)
    Me.SurveyList.Requery
    End Sub

  5. #5
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    Private Sub TabCtl75_Click()
    SurveyList.Requery
    End Sub

  6. #6
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    I have a listbox which I need to requery when my page opens. I have tried many different ways of doing this but all without luck.

    The listbox is based on a page/tab of a form. It is on a tab which doesn't load up when the form first opens. The user has to click the tab before it loads.
    I have a some questions regarding your original request.
    1. Why do you want the listbox to requery when the page or form opens?
    2. What do you mean by the "The TAB does not load up when the first opens"?
    3. How do yo know that the requery of the listbox is not working and are there other fields dependent on this listbox?

  7. #7
    Join Date
    Nov 2008
    Posts
    59
    I can't believe how much I am struggling with this! I really thought there might have been an easy solution.

    Anyway, I have tried:
    Private Sub listbox_GotFocus()
    DoCmd.Requery "listbox"
    End Sub

    But also without any luck.

    Poppa Smurf, in answer to your questions:

    1. The listbox gives a rundown of information that is important to each client. If it doesn't load automatically it is possible that the user might miss this information. Hence, why I am trying to get this to automatically load.

    2. There are 3 tabs in the form. The tab with the listbox is not the main page, so requires clicking on its tab to see the information

    3. The requery works but not the way I want it. When on any page I can press F9 or click in the Listbox and the correct information will load up, but I can't get it to load without having to perform some action. Sometimes the information will carry from one record to the next without refreshing, which would be extremely confusing for the user!

    If anyone has anymore suggestions I would be really grateful. I'm sure this can't be so complex!

    Thanks
    Russ

  8. #8
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    On your first page of the new record when the user selects the first field to enter the data in the After Update of the field then do your requery.

    If a new record you could use the On Current event for the form to do your requery.

  9. #9
    Join Date
    Nov 2008
    Posts
    59
    Yes!

    On Current works a treat!! Thanks so much for your help!

    I didn't really notice OnCurrent before, was trying out all the other ones below. Thanks for letting us know about that one though. Much appreciated!

    Thanks
    Russ

Posting Permissions

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