Solved

Requery a listbox

Posted on 2007-11-29
8
407 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 - 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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