Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I like to convert tables (100+) living in access database to a geodatabase tables, sorting them and deleting unnecessary fields in each table at the same time. I figured I use the Sort_management method to convert and sort the tables followed by DeleteField_management method to delete the fields. Here is the code that I have written,

import arcpy

from arcpy import env

env.workspace = "E:\Database Project\ACS Estimate 2011\ACS 2011 Tables.mdb"

tableList = arcpy.ListTables()

for table in tableList:

    out_dataset = "E:\Database Project\ACS Estimate 2011\Data\To Database\Seq Tables.gdb"

    #Process: Sort
    arcpy.Sort_management(table, out_dataset, "GEOID ASCENDING", "UR")

    #Process: Delete Field
    arcpy.DeleteField_management(out_dataset, "FILEID;FILETYPE;STUSAB;CHARITER")

Here is the error message that I am getting,

enter image description here

Any help is appreciated. Thank you in advance.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

your out_dataset points to a gdb, not a feature classs or table as required.

you could try this, which should give each table in the output database the same name it had in the input database:

out_dataset = r"E:\Database Project\ACS Estimate 2011\Data\To Database\Seq Tables.gdb" + "\\" + table

edit: forgot to make it a raw string

share|improve this answer
    
Thanks, I ll give it a try. –  Raj Mar 12 '13 at 15:29
    
Now, I have following error message:ExecuteError:ERROR 999999: Error executing function. Failed to execute (Sort). –  Raj Mar 12 '13 at 15:32
    
Ok. I figured it out. I had to convert the access tables to geodatabase tables using table to table tool and use those gdb tables to perform sort and delete operations. Thank you for your help. –  Raj Mar 12 '13 at 15:50
    
No need to use table to table tool, see my updated anwser. –  artwork21 Mar 12 '13 at 16:01

The problem is that the out_dataset needs to point to a feature class table. Right now you have it pointed just to the geodatabase.

This should work (work path slashes are going the wrong way '\' need '/'):

import arcpy

from arcpy import env

env.workspace = "E:/Database Project/ACS Estimate 2011/ACS 2011 Tables.mdb"

tableList = arcpy.ListTables()

for table in tableList:

    out_dataset = "E:/Database Project/ACS Estimate 2011/Data/To Database/Seq Tables.gdb" + "//" + table

    #Process: Sort
    arcpy.Sort_management(table, out_dataset, "GEOID ASCENDING", "UR")
share|improve this answer
    
Ok. I understand your point. How do I accomplish that? I want the tables to be named exactly same as the input. –  Raj Mar 12 '13 at 15:07

I strongly recommend you read the Help file on the sort tool. Your code does not have the correct syntax for the sort field parameters. Also your output dataset is the geodatabase not the table. Looking at the help file suggests to me you might need to reset the workspace too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.