Add multiple files to ListBox

justice8965

Registered User.
Local time
Today, 08:39
Joined
Aug 25, 2009
Messages
32
Hey all,

So I have a program where the user selects some spreadsheets with information they want to import. They can select as many as they like, these are then added to a ListBox. The user than clicks the Import button to do some calculations and the actual import.

This works fine when they select 5 files, or less. However, if they try to select any more than 5, something goes wrong, and I'm not sure what. Here is my code.



lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
If IsArray(result) Then
Dim i As Integer
For i = 0 To UBound(result)
'MsgBox result(i)
Forms!ElectricImport!filesListBox.RowSourceType = "Value List"
Forms!ElectricImport!filesListBox.RowSource = AddItem(Forms!ElectricImport!filesListBox.RowSource, result(i), 0)
Next i
Else
'MsgBox result
Forms!ElectricImport!filesListBox.RowSourceType = "Value List"
Forms!ElectricImport!filesListBox.RowSource = AddItem(Forms!ElectricImport!filesListBox.RowSource, result, 0)
End If
Else
MsgBox result
End If


The part that is bold and underlined is where the code checks to see if multiple files have been selected, by checking to see if the variable is an array or not. If they select more than 5 files, this is where the program skips. Why does it create an array for 5 or under, but not over?

Any help would be greatly appreciated.
 
No error, it just skips the part that I highlighted which it shouldn't. It doesn't add anything to the list box.
 
the first thing I would do is add some debugging code

Code:
lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result               As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
                               Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
                               DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
    Debug.Print "Is array : " & IsArray(result)
    Debug.Print "Result Is : " & result

    If IsArray(result) Then
        Dim i            As Integer
        For i = 0 To UBound(result)
            Forms!ElectricImport!filesListBox.RowSourceType = "Value List"
            Forms!ElectricImport!filesListBox.RowSource =AddItem(Forms!ElectricImport!filesListBox.RowSourc e, result(i), 0)
        Next i
    Else
        Forms!ElectricImport!filesListBox.RowSourceType = "Value List"
        Forms!ElectricImport!filesListBox.RowSource = AddItem(Forms!ElectricImport!filesListBox.RowSourc  e, result, 0)
    End If
Else
    MsgBox result
End If

The check the immediate window in the VBA editor to see what the value are (if it is now visible then go to TOOLS > IMMEDIATE WINDOW)
 
a sample of your database - i don't need the files you are trying to attach
 
I'm not exactly sure what you mean by that (I'm somewhat new to this).
 
basically take a copy of your database, delete anything not relevant, delete any data if it's confidential (for this issue I'm not sure any data is required anyway.

then upload it here by going into advanced mode (button next to "post quick reply" and attach the file.
 

Users who are viewing this thread

Back
Top Bottom