Link to home
Start Free TrialLog in
Avatar of Jonathan Gray
Jonathan Gray

asked on

How do I change the name of a table created by Saved Imports

Import an excel file into Access 10 using the Saved Imports in External data. However the table created is saved using the wrong name, is there a method to change the name of the created table. Its a very complicated import, where I have changed the formats, so I don't want to recreate the import from scratch, just want to know is there a way to modify without code. If not, is there a dummies way of doing it using code.

Thanks
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

you can right-click on the name in the Navigation pane and choose Rename when the process is done. If that is not what you want to do, please explain in more detail, thank you.
You must be using the newer "saved import" method.  So many people had trouble understanding how to use and manage Import/Export specs, that MS decided to hide them rather than clean up the interface.  Personally, when I run into apps that use this method, I modify the process to use the appropriate "Transfer" method and Import/Export spec.  That way the import/export is exposed and it is easy to change it in the future as well as now giving me control over all parts of the name as well as the source/destination folders.

To rename a table (or other object), select it, and then change its name property.  The code below assumes that your object name does not include embedded spaces or special characters.  If your name does not conform to proper standards, the syntax will be slightly different.

Public Sub testrename2()
    Dim db As DAO.Database
    Dim td As DAO.TableDef
    
On Error GoTo Err_Proc

    Set db = CurrentDb
    Set td = db.TableDefs!OldName
        td.Name = "NewName"
      
Exit_Proc:
    Exit Sub
Err_Proc:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & "-" & Err.Description
            Resume Exit_Proc
    End Select
End Sub

Open in new window

Avatar of Jonathan Gray

ASKER

In reply to crystal, you can't rename saved imports, you run the import and it creates a table, all in one process.

In reply to  PAtHartman, when I go into table properties, can only hide attributes. Please can you explain fully, where do I enter the code, as I'm a code novice. Plus is this code a permanent solution for when I run the import every time.
you asked for a way to modify without code ... the way to do that is to change the name when done. I gave you steps to do it manually and Pat gave you code you can run instead.

You can't make the process flexible and NOT run code or do something manually. If you need to automate this, you probably need to start learning VBA -- plenty of folks here can help you better if you can understand more about what they give you.

It is not hard to learn the basics of VBA ... it makes sense. The 3 chapters (all I wrote) posted here will not take you long to read. Chapter 1 ... maybe 20 minutes. Chapters 2 and 3 you can read for logic but not memorize -- they are there for reference and foundation.

Learn VBA
http://www.AccessMVP.com/strive4peace/VBA.htm

this should give you the knowledge you need to understand basic code.
Jonathan,
As I already said, you are better off changing your import to a method that gives you some control over the moving parts.

The code I wrote should be placed in a standard module and the call to it should follow the code that runs the import.

Pleas change the procedure name to something meaningful before putting it in the app.  So, "testrename2" could be "RenameFile"  and then you would call it:

Call RenameFile
Pat said, "control over the moving parts" ... assume she has helped you on other threads and knows more about your project. It would be good to step back and spend a bit of time padding your perspective with some studying. Things you need now, and in the future, can be accomplished with VBA (Visual Basic for Applications), which is the universal programming language for Microsoft Office desktop products.

The import you are now launching with specifications can be modified as you desire with knowledge of VBA.  You could then import from a saved specification and then rename the final table.

>> saved using the wrong name <<

What is the name of the Excel sheet or range that the data is coming from? What does Access call the table?

what do you want the name to be?
The point is that if you import using DoCmd.TransferText  ....  you do NOT need to rename anything since you specify the name in the instruction.  Because the name is visible and modifiable, you can include code that constructs it out of variables if necessary.  The TransferText allows you to create an import/export spec and save it.  You then refer to the spec by name in the TransferText instruction.  To use TransferText, you must first do the import or export manually.  On the last wizard form, press the Advanced button, name the spec  (short and sweet is best).  Once it is named and saved, you refer to the spec in the TransferText instruction.
here is a help page for the TransferText syntax:
https://msdn.microsoft.com/en-us/library/office/ff835958(v=office.15).aspx

As Pat said, you can specify the TableName -- so if you are going to use VBA at all, it makes sense to use it to launch the import and then name as you wish (how do you wish to name the table? is there already a table with the same structure in your database? if so, why? perhaps you can add another field to differentiate the import that is updated after the import?)
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.