Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add FieldNames from Table into ComboBox

Status
Not open for further replies.

MacroAlan

Programmer
Dec 4, 2006
134
US
I have a piece of code:
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
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.
 
In Access it is possible to set the RowSourceType of a combo to Field List and the RowSource to a table or query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top