*EDIT*
I realized after posting this question that the code didn't quite come through as formatted as I remember the last time I posted something. Has the formatting changed, or did I do something wrong? Thanks!
Hello,
I have a script that I am using to iterate through a list of all fields in a feature class, run summary statistics on itself to get a table of all entries, and then creates a file geodatabase copy as well as an excel copy of the table. The tool that I have is working seemingly well, but I end up getting an error at the end.
The code:
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Name: Database Check</SPAN>
<SPAN class="comment token"># Author: Coy Potts</SPAN>
<SPAN class="comment token"># Description: This tool runs a summary on all feature class fields to check for inappropriate entries.</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Import system modules</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">import</SPAN> datetime
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Set universal variables</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
generalFeatures <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'OSP Mapping Layers\General Features'</SPAN>
dateToday <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>date<SPAN class="punctuation token">.</SPAN>today<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
outPath <SPAN class="operator token">=</SPAN> r'<SPAN class="string token">"local_shared_drive"</SPAN>
generalVar <SPAN class="operator token">=</SPAN> <SPAN class="string token">"general"</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Create the workspace for the statistics documents</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="comment token"># Create a dated folder</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
datedFolder <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>dateToday<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create a dated folder to store the tables</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFolder_management<SPAN class="punctuation token">(</SPAN>outPath<SPAN class="punctuation token">,</SPAN> datedFolder<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="comment token"># Create a dated geodatabase</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
outGDB <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>dateToday<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">".gdb"</SPAN>
<SPAN class="comment token"># Create a dated file geodatabase</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFileGDB_management<SPAN class="punctuation token">(</SPAN>datedFolder<SPAN class="punctuation token">,</SPAN> outGDB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CURRENT'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Run Statistics on the General Features feature class</SPAN>
<SPAN class="comment token"># ###################################################################################################</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
inFC <SPAN class="operator token">=</SPAN> generalFeatures
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
fieldCount <SPAN class="operator token">=</SPAN> len<SPAN class="punctuation token">(</SPAN>fields<SPAN class="punctuation token">)</SPAN>
i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="comment token"># Iterate through each General Features field, exporting an associated table and excel sheet</SPAN>
<SPAN class="comment token"># ########################</SPAN>
<SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> fields<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">while</SPAN> i <SPAN class="operator token"><</SPAN> fieldCount<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
i <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
fieldVar <SPAN class="operator token">=</SPAN> fields<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN>
statsFields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>fieldVar<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"COUNT"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
caseFields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>fieldVar<SPAN class="punctuation token">]</SPAN>
outTable <SPAN class="operator token">=</SPAN> generalVar <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_"</SPAN> <SPAN class="operator token">+</SPAN> fieldVar
<SPAN class="comment token"># Execute SummaryStatistics</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Statistics_analysis<SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">,</SPAN> outTable<SPAN class="punctuation token">,</SPAN> statsFields<SPAN class="punctuation token">,</SPAN> caseFields<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
inTable <SPAN class="operator token">=</SPAN> inFC
saveGDB <SPAN class="operator token">=</SPAN> outPath <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>dateToday<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> outGDB
<SPAN class="comment token"># Execute TableToTable</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TableToTable_conversion<SPAN class="punctuation token">(</SPAN>inTable<SPAN class="punctuation token">,</SPAN> saveGDB<SPAN class="punctuation token">,</SPAN> outTable<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Summary table created for the "</SPAN> <SPAN class="operator token">+</SPAN> fieldVar <SPAN class="operator token">+</SPAN> <SPAN class="string token">" field!"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
inTable <SPAN class="operator token">=</SPAN> outTable
outXLS <SPAN class="operator token">=</SPAN> outPath <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>dateToday<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> generalVar <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_"</SPAN> <SPAN class="operator token">+</SPAN> fieldVar <SPAN class="operator token">+</SPAN> <SPAN class="string token">".xls"</SPAN>
<SPAN class="comment token"># Execute TableToExcel</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TableToExcel_conversion<SPAN class="punctuation token">(</SPAN>inTable<SPAN class="punctuation token">,</SPAN> outXLS<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Excel sheet created for the "</SPAN> <SPAN class="operator token">+</SPAN> fieldVar <SPAN class="operator token">+</SPAN> <SPAN class="string token">" field!"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"General Features summary tables have been created for all fields!"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This script runs through and does exactly what it is meant to do for each field, but then I get this error:

I have 4 other feature classes that I would like to eventually add onto this script to run through the exact same process for each of the feature classes, but I can't get it to work on the second feature class with this error getting triggered after the first feature class wraps up. Any ideas why it is giving me a field type error even though the tool has technically already exported out each of the fields to tables?
*SIDE NOTE* (let's fix the problem above first)
The tool needs another minor tweak as well in the fact that in its current state, it creates a copy of the table in my default database before it creates a copy in my created database via the table to table function, which obviously poses the problem of having pre-existing tables when running subsequent times after the first. I had to try various workarounds when trying to get this to work initially. For instance, whenever I have an env.workspace declared under the initial while loop's local variables, I would later get an error stating that the table already existed when I tried the table to table function. However, if I removed the table to table function and relied on the env.workspace table created down in the table to excel function, I would get an error saying that the table couldn't be read.