Solved

Requery a listbox

Posted on 2007-11-29
8
409 Views
Last Modified: 2012-06-27
There are several listboxes on a tab control.  I would like to be able to requery through all the listboxes without regard to the name of the listbox.  This way, if there are new listboxes added to the form, they will be requeried at the same time.

sub requeryAll()

Me.txt_A.Requery
Me.txt_B.Requery
Me.txt_C.Requery
Me.txt_D.Requery
Me.txt_E.Requery
Me.txt_F.Requery
Me.txt_G.Requery
Me.txt_H.Requery
Me.txt_I.Requery
Me.txt_J.Requery
Me.txt_K.Requery
Me.txt_L.Requery
Me.txt_M.Requery
Me.txt_N.Requery
Me.txt_O.Requery
Me.txt_P.Requery

end sub

Thanks

Paul
0
Comment
Question by:pgoulet_fsac_info
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 20378583
sub requeryAll()

Dim ctl As Control
For Each ctl In Me.Controls
    Select Case ctl.ControlType
        Case acListBox

                Me(ctl.Name).Requery

    End Select
Next

End Sub
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20378830
It's a bit of a brute force approach but it will work and it only takes one line of code to do if you prefer this approach.
Me.Recalc

Open in new window

0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20378836
Put Another Way....
Sub requeryAll()
     Me.Recalc
End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 20379548
The only problem with ReCalc is that *every* calculated control gets requeried - which my not be desirable.

mx
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20379584
Hence the part about it being a "brute force" approach.  

It's simple, but comes at the price of performance and affect to every control as pointed out by DatabaseMX.

Even so, it seemed worthy of mention, some find simple, even if blunt, preferable to something more sergical that requires more code.  Even so, DatabaseMX is very correct, although if we are looking for down sides to the approach one should certainly consider performance along with the fact that everything is recalculated as MX pointed out.  If one can live with the impact of Recalc it's simple but that's it, it wins no points for the more surgical and precise approach MX provided.
0
 
LVL 75
ID: 20379599
Rick ... hey ... nothing wrong with Me.Recalc ... a good solution ... as long as there are not other calculated controls.  The weird thing about Recalc ... if you do it from a Sub Form, it seems to also recalc the main form also, which I have always found annoying.

So ... of course it's 'worthy of mention' ...

mx
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20379627
Thanks mx.  :)
0
 

Author Closing Comment

by:pgoulet_fsac_info
ID: 31411829
I am always amazed at how quickly I am able to get a great response.  Of course working with a great question helps too.

Thanks for the support.

Paul
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Report formatting issue 5 71
Conditional Format if Between Dates 9 43
ODBC failure when running MSACCESS query a second time. 5 53
SUBFORM on ACCESS 2013 8 29
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question