?
Solved

Requery a listbox

Posted on 2007-11-29
8
Medium Priority
?
411 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

765 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