Solved

Requery a listbox

Posted on 2007-11-29
8
410 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
Technology Partners: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

719 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