Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to F9 to requery combo boxes

Misc

Alternative to F9 to requery combo boxes

by  markphsd  Posted    (Edited  )
F9 is the short cut to requery combo and listboxes on forms, but it means you have to tell your users to use it, and they have to remeber to use it.

This is an alternative that you can use on all of your forms when you modify the data in a combo box. Rather than using a requery even for each combo box, it will find any combo boxes in the main forms of you application that are open. I don't have a sub form requery code written but i'm sure i'll get around to it soon enough:

Place this in a module and call it whenever you modify the contents of combo or list boxes.

Public Sub RefreshComboBoxes()

On Error GoTo eh:

Dim frm As Form
Dim obj As Object
Dim oCtl As Control
Dim sbfrm As Form
Dim oCtlSub As Control

For Each obj In CurrentProject.AllForms
If CurrentProject.AllForms(obj.Name).IsLoaded Then
Set frm = Forms(obj.Name)
For Each oCtl In frm
Select Case oCtl.ControlType
Case acComboBox, acListBox
oCtl.Requery
End Select
Next
End If
Next obj

Exit Sub
eh:

' insert your own error routine here.


End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top