Hi
I import a table into access using transfer text with the code below. The code asks the user for the name of the table at runtime. I then want to run a query on the table with the same code but how can I do this if the table name is defined by the user.
Thanks
I import a table into access using transfer text with the code below. The code asks the user for the name of the table at runtime. I then want to run a query on the table with the same code but how can I do this if the table name is defined by the user.
Thanks
Code:
[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Option Compare Database[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman] [/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Private Sub import_Click()[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]On Error GoTo Err_Import_File_Click[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim strFile_Path As String[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim strTable As String[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]'Prompt user for file path[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]strFile_Path = InputBox("Please enter file path and file name")[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]'Prompt user for name of table to create for imported data[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]strTable = InputBox("Please enter name of new table")[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]DoCmd.TransferText acImportDelim, "spec_import", _[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman] strTable, strFile_Path[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]DoCmd.OpenQuery "query1", acViewNormal[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Exit_Import_File_Click:[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Exit Sub[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Err_Import_File_Click:[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]If Err.Number = 3011 Then[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]MsgBox strFile_Path & " is not a valid path, please try again", vbExclamation, "Invalid File Path"[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Else[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]MsgBox Err.Description[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End If[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Resume Exit_Import_File_Click[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End Sub[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]