Gotcha. And you provide the final table name to the Wizard that starts when
you select the file and click Import. Other than instructing the user to
always specify some standard table name for the import in the last panel of
the Wizard, I can't think of any clean way to do this with a macro. Your
Rename would then specify that "standard" table name to rename.
Of course the real solution is to use Visual Basic, prompt the user for the
file name to import, and then supply that as a variable to the
TransferSpreadsheet method with a known table name.
You could write a simple function to do that and then call it with RunCode.
Put this in a module you create from the database window:
Public Function GetSpreadSheet() As Integer
Dim strFileName As String
' First set an error trap to skip errors
On Error Resume Next
' Delete the old table
CurrentDb.TableDefs.Delete "TempExcelTable"
' Set a generic error trap
On Error GoTo GetSpreadSheet_Err
' Ask the user for the file name
strFileName = InputBox("Enter the path and file name you want to import.",
_
"Enter Spreadsheet File")
If Len(strFileName) = 0 Then
MsgBox "You didn't enter anything."
GetSpreadSheet = False
Exit Function
End If
' Think we got a name, try to import it
DoCmd.TransferSpreadSheet acImport, , "TempExcelTable", _
strFileName, True ' True assume first row is column names
MsgBox "Import successful."
GetSpreadSheet = True
GetSpreadSheet_Exit:
Exit Function
GetSpreadSheet_Err:
MsgBox "Error encountered: " & Err & ", " & Error
GetSpreadSheet = False
Resume GetSpreadSheet_Exit
End Function
If you use the above code, the imported spreadsheet will always be called
"TempExcelTable" - or you can substitute any name you like in the code. You
won't have to do a rename.
--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
John Dionne said:
John
I am using the RunCommand Action along with "import" which opens a
selection box just like menu selection file open or import. This action
does not require a parameter such as file name or table.