Calculate Field Error

5499
2
06-26-2012 05:47 AM
davidmetzler
New Contributor II
Greetings,
     This is most likely a simple question but I just cant seam to lick it. I have this code that I want to calculate a field for me. the field is STRING, 8 Characters. There is a domain on this field with some coded values. I exported a dbf of the feature to confirm the value should be STAK. Every time I run this bad boy I get the attached error. I have tried both VB and PYTHON code but nothing seems to work (although the error reporting from python looks better).
     I have a feeling that there is one simple thing I'm not doing, can someone please help?


import os
import arcpy

#Workspace will be the database for export
arcpy.env.workspace = r"P:\folder\rmp_2_5_2.mdb"
#calculate fields
arcpy.CalculateField_management ("WELL_PT", "W_STATUS", "STAK", "VB")



[ATTACH=CONFIG]15481[/ATTACH]


Error:
The calculated value is invalid for the row with ObjectID=2011. For Example, the calculated value may be too large for the field or you may be trying to add a string to a number field. this row will not be updated.



Thanks,

The D
Tags (2)
0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor
The problem is that in VB you need to wrap strings in quotes. When you pass what you've written into the field calculator from Python, it strips off the quotes of the parameters turning "STAK" into STAK. Basically, you just need an extra set of quotes around the expression so it's left with quotes once the first set have been stripped.
arcpy.CalculateField_management ("WELL_PT", "W_STATUS", ' "STAK" ', "VB")
davidmetzler
New Contributor II
Thank you very much. This worked like a charm. here is the final code:


import os
import arcpy

#Workspace will be the database for export
arcpy.env.workspace = r"P:\folder\rmp_2_5_2.mdb"
#calculate fields
arcpy.CalculateField_management ("WELL_PT", "W_STATUS", ' "STAK" ', "VB")


Happy GISing,
   Dave
0 Kudos