Skip to main content

After hiding a field, Table to Excel gives RuntimeError Cannot find field ''

I'm trying to export a Table View to Excel (using arcpy). It works well if the Table View doesn't have hidden fields. As soon as I hide the OBJECTID when creating the View, I get a runtime error (Cannot find field '').

When I try to do the same in the ModelBuilder, it works. Any idea why the Python script fails to execute?

arcpy.MakeTableView_management(TEMP_Consumption, TEMP_Consumption_View, "", "", "OBJECTID OBJECTID HIDDEN NONE;Customer_Name Customer_Name VISIBLE NONE")
arcpy.TableToExcel_conversion(TEMP_Consumption_View, ExportFile, "ALIAS", "CODE")

The full error message:

Traceback (most recent call last):
File "C:\Users\Daniel\Desktop\exportconsumptions1.py", line 84, in <module>
arcpy.TableToExcel_conversion(TEMP_Consumption_View, ExportFile, "ALIAS", "CODE")
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 81, in TableToExcel
raise e
ExecuteError: 
Traceback (most recent call last):
File "c:\program files (x86)\arcgis\desktop10.3\ArcToolbox\Scripts\TableToExcel.py", line 222, in <module>
arcpy.GetParameter(3))
File "c:\program files (x86)\arcgis\desktop10.3\ArcToolbox\Scripts\TableToExcel.py", line 192, in table_to_excel
for row in cursor:
RuntimeError: Cannot find field ''

Failed to execute (TableToExcel).