I have a piece of code:
That opens a dialog box and allows the user to select a file that will be loaded into a “tempTable” for use in the next steps.
In the next step, I want to read the FieldNames from this table and add them to a comboBox on my form. The user is going to use the field names to choose what action to perform.
Loading the tempTables is working great. How do I read the filenames and squirt into comboBox?? Fill array and use AddItem? The file data is immaterial at this point.
Code:
Sub OpenDataSource(ProcName)
[red]'Passing form_name so code can be re-used[/red]
Dim cmdlgOpenFile As New clsCommonDialog
Const clngFilterIndexAll = 2
cmdlgOpenFile.Filter = "Text Files (*.txt)|*.txt|Excel Files (XLS)|*.xls|All Files (*.*)|*.*"
cmdlgOpenFile.FilterIndex = clngFilterIndexAll
[red]'this is where the dialog opens[/red]
cmdlgOpenFile.ShowOpen
[red]'returns your full file name.[/red]
FileName = cmdlgOpenFile.FileName
Debug.Print ProcName
[red]'hence no len, no name...[/red]
If Len(FileName) = 0 Then Exit Sub
ProcName.txtDataSource.Value = FileName [red]'not working?[/red]
If Right$(FileName, 3) = "txt" Then
DoCmd.TransferText acImportDelim, , _
"tempImport", FileName, True [red]'If Text[/red]
Else
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel9, "tempSpread", FileName, True
End If
[red] 'Once the data is in the temp file, FieldNames need
'to be applied to ComboBoxes for next step[/red]
End Sub
In the next step, I want to read the FieldNames from this table and add them to a comboBox on my form. The user is going to use the field names to choose what action to perform.
Loading the tempTables is working great. How do I read the filenames and squirt into comboBox?? Fill array and use AddItem? The file data is immaterial at this point.