Solved

Requery a listbox

Posted on 2007-11-29
8
399 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
  • 4
  • 3
8 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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
 
LVL 75
ID: 20379548
The only problem with ReCalc is that *every* calculated control gets requeried - which my not be desirable.

mx
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now