I am trying to write some code that will loop through selected items in a multi-select listbox and perform the transferspreadsheet operation for each item. However I am running into some trouble. Currently, I am getting an "invalid use of null" error.
Here is what I have so far.
Private Sub Command12_Click()
If file_list.ListIndex = -1 Then
'If ListIndex is -1, nothing selected
MsgBox "Nothing was selected!"
Else
'If ListIndex not -1 run transfer spreadsheet
Dim varItem As Variant
Dim FilePath As String
Dim FileSelection As String
For Each varItem In Me.file_list.ItemsSelected
FileSelection = file_list.Value
'DoCmd.TransferSpreadsheet acImport, , _
"tbl_Data", "C:\Documents and Settings\rbrady\Desktop\" & FileSelection, True, "A1:F40"
Next varItem
End If
Any ideas where I am going wrong, or perhaps suggestions on how to structure the code better?
Thanks
Here is what I have so far.
Private Sub Command12_Click()
If file_list.ListIndex = -1 Then
'If ListIndex is -1, nothing selected
MsgBox "Nothing was selected!"
Else
'If ListIndex not -1 run transfer spreadsheet
Dim varItem As Variant
Dim FilePath As String
Dim FileSelection As String
For Each varItem In Me.file_list.ItemsSelected
FileSelection = file_list.Value
'DoCmd.TransferSpreadsheet acImport, , _
"tbl_Data", "C:\Documents and Settings\rbrady\Desktop\" & FileSelection, True, "A1:F40"
Next varItem
End If
Any ideas where I am going wrong, or perhaps suggestions on how to structure the code better?
Thanks