
Populate List Box with Large List
Hi Paul,
use this as a template for creating your own. You will need to add Microsoft
Scripting Runtime to your project first. the FSO is an extremely fast method
to access text data. This particular example loads approximately 250
agencies into a combo box in a dialog in less than a second. The text
"~Agencies" in my text file identifies the beginning of the list of
Agencies. I also have list of other types in the same file, but used in
other situations. The whole setup is easily maintained in a single text
file.
' The first part is to get the Agencies names from the file
lcb_globals.txt
Dim myFSO As FileSystemObject
Dim theFile As File
Dim ts As TextStream
Dim aStr As String
Dim i As Integer
Dim doIt As Boolean
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set theFile = myFSO.GetFile("C:\lcb_globals.txt")
Set ts = theFile.OpenAsTextStream(ForReading)
' Read in the names from the file & add to combobox.
i = 0
doIt = False
Do While ts.AtEndOfStream <> True
aStr = ts.ReadLine 'reads each line
If aStr = "~Agencies" Then 'this is the identifier for the
beginning of the agency list
doIt = True
ElseIf doIt Then
If aStr = "" Then 'the end of the list was reached (a blank
line)
doIt = False
Else
If i = 0 Then NewRegDlog.AgencyBox.Value = aStr
NewRegDlog.AgencyBox.AddItem (aStr)
i = i + 1
End If 'empty string
End If ' doit true
Loop
Hope this helps and have a great day.
--
~~~~~~~~~~~~~~~~~~~~~~
Stephen Lang
401 S. Carson Street
Carson City, NV 89703
775.684.6830
GMT-8
slangatlcb state nv us
~~~~~~~~~~~~~~~~~~~~~~
To respond via e-mail:
Quote:
> I am looking for a way to put a large, easily edited, list into a list box
in
> word. Using the Add.Item will not work for this. I can't count on all
users
> having excel or access. Therefore, an .ini file would work, but I don't
know
> how to access it.
> Anybody have experience or success with such a project? Any help would be
> greatly appreciated.
> Paul Sweeney