Q:
I am loading a list box with about 3,000 names in it, but it takes
a long time to do this, the code I am using is IF NOT EOF then LOAD LOOP.
you probably get the idea. Is there an API call to load this faster, or do
you know of any other way to load it faster. I am using VB 3.0 and access 2.0.
Keith Bauer ris@albany.net
A:
first.. are you reading in 3000 names in a listbox or is your
database 3000 records big and you just want a selection into the
listbox? It's a lot to show in a listbox...
anyway I think your code looks like this..
'open recordset
set rs = db.openrecordset(tablename)
Do While Not rs.EOF
list1.additem rs.Fields(0).Value
rs.MoveNext
Loop
There's not much you can do to make it faster... You can make the
list-box invisible before starting the loop and visible after you're
done. But that's just 'cosmetic'.
You can consider to 'narrow' you database:
Suppose you're looking for a name but you're not sure about the
right writing. You can make an inputbox where your user can give some
input where to search for. Then you make an SQL-string and load your
listbox with the found names.
like this:
'input user in Text1.Text
vSearchFor = "*" & Text1.Text & "*"
SQL$ = "SELECT * FROM " & yourtable
SQL$ = SQL$ & " WHERE name LIKE '" & vSearchFor & "'"
'open recordset
set rs = db.openrecordset(SQL$)
Do While Not rs.EOF
list1.additem rs.Fields(0).Value
rs.MoveNext
Loop
Suppose you user look for 'smit'; giving the above code the listbox
will show all the names with 'smit' in it -> 'smith', 'smits' but
also 'messersmith'.
Return