Requerying Listbox

T

Tony

Hi All,

I'm having trouble getting a listbox to requery. What I have is a listbox
bound to a query. Typically, when the user opens the form there are no
records to show in the listbox, so I hide it and display a text box on top
of it that says "No Records". After the user runs some code on the form
that puts records into tables that the query looks at, I'd like to requery
the listbox so that the records are shown. Using Me.lstBoxName.Requery
works when the listbox initially has records, but if it has no records to
display when the form is first opened, this does not work. The process I'm
using goes something like this:

1) Listbox is empty and hidden when form is opened
2) User runs code that populates tables from which the query the listbox is
bound to pulls data. If I run the query directly at this point, it shows
the correct records
3) The listbox is set to visible
4) The listbox is requeried
5) If the listbox had records when the form was opened, the requery works
and the correct records are shown. If there were no initial records for the
listbox to display, only a blank row is shown

Any help that can be offered is appreciated.

Thanks & Ciao,

Tony
 
K

Klatuu

I use a similar trick with a twist. Rather than hide the list box, I set
it's height to 0 in design view, but when I want it displayed, I set it to
the desired height. Rather than requery, I reestablish the row source.

Me.MyListBox.RowSource = "SELECT A_Field FROM A_Table WHERE EveryYouWant =
'Cool';"
Me.MyListBox.Height = 3180

(height is in twips which are 1440 per inch)

(but I still can't convert Furlongs Per Fortnight to Miles Per Hour)
 
T

Tony

Hey Klatuu,

Thanks for the response. I'll give that a try, hopefully it'll slim down
the code a bit as well.

Thanks,

Tony
 
T

Tony

Well, no dice. The control resizes but the data still won't refresh. Any
other suggestions?

Thanks,

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top