Skip to main content

Working with Arrays

Hello,
I am working on a project that involves populating multiple drop down lists via arrays with the field names from a previously selected database. There is also an array that is being used to populate information for another part of the process. The problem I am running into is that once I add in my 3rd drop down menu (4th time an array is being used) I keep getting the error: "Subscript out of range". Am I missing something that would clear the array each time I use it? Below are some sections of my script:

Within my displayIt function where I call the function:
Case 2
Select Case ControlId$ 'if PushButton1 selected then call the getFile function to obtain the filename
Case "PushButton1"
sFilename = getFile()
bExitFun = false 'don't close the dialog

Call getUniqueIDField()
DlgListBoxArray "DropListBox3", Listbox3$

Call getNameField()
DlgListBoxArray "DropListBox4", Listbox4$

Call getWithholdingField()
DlgListBoxArray "DropListBox5", Listbox5$

Case "DropListBox3" 'called if the user selects or changes a field
sUniqueIDField = Listbox3$(SuppValue%) 'get the field name

Case "DropListBox4" 'called if the user selects or changes a field
NameField = Listbox4$(SuppValue%)

Function getNameField()
Dim db As database
Dim table As table
Dim field As field
Dim i As Integer

Set db = client.OpenDatabase(sFilename)
Set table = db.TableDef
ReDim listbox4$(table.count)
For i = 1 To table.count
Set field = table.GetFieldAt(i)
listbox4$(i) = field.name
Next i

Set field = Nothing
Set table = Nothing
db.close
Set db = Nothing
Call sortArray2(listbox4)
End Function

Private Function sortArray2(MyArray() As String)
Dim lLoop As Integer
Dim lLoop2 As Integer
Dim str1 As String
Dim str2 As String
For lLoop = 0 To UBound(MyArray)

For lLoop2 = lLoop To UBound(MyArray)
If UCase(MyArray(lLoop2)) < UCase(MyArray(lLoop)) Then
str1 = MyArray(lLoop)
str2 = MyArray(lLoop2)
MyArray(lLoop) = str2
MyArray(lLoop2) = str1
End If
Next lLoop2
Next lLoop
MyArray(0) = "Select Field"
End Function

The website encountered an unexpected error. Try again later.