<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Field Calculator using input from a form in VBA in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/field-calculator-using-input-from-a-form-in-vba/m-p/707599#M18928</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a form for a user to input an adjustment factor table.&amp;nbsp; It allows the user to input a year for each month as well as the given adjustment factor, which is dependent on the day of the week in in that specific month. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it looks something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;January&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[year]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[mon]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[tues]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[wed]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[ect...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;February&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[year]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[mon]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[tues]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[wed]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[ect...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ect..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then at the bottom is a command button to store the entered values in the Adjustment table.(Which is a table that has two fields Date, which already stores all the individual days in the year, and Adjustment)&amp;nbsp; I want the command button at the bottom to run a field calculation checking the year and the day of week from the date field then using the correctly selected value entered in the form as the value for the Adjustment field. So really it is just an elaborate if then statement.&amp;nbsp; I just dont know how to make the field calculator look at the form for a value.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what i have already.&amp;nbsp; I know the syntax for the .Expression is wrong but i am not sure how to make it work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Private Sub cmdSave_Click()

&amp;nbsp; On Error GoTo EH
&amp;nbsp; 
&amp;nbsp; Dim pDoc As IMxDocument
&amp;nbsp; Set pDoc = ThisDocument

&amp;nbsp; 'set table to ADT_Adjustment&amp;nbsp; **must be the top table in the Table of Contents
&amp;nbsp; 
&amp;nbsp; Dim pTc As ITableCollection
&amp;nbsp; Set pTc = pDoc.FocusMap
&amp;nbsp; Dim pTable As ITable
&amp;nbsp; Set pTable = pTc.Table(0)
&amp;nbsp; 
&amp;nbsp; ' This calculation is to be done outside of an edit session.
&amp;nbsp; Dim pEditor As IEditor
&amp;nbsp; Dim pID As New UID
&amp;nbsp; pID = "esriCore.Editor"
&amp;nbsp; Set pEditor = Application.FindExtensionByCLSID(pID)
&amp;nbsp; If pEditor.EditState = esriStateEditing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "This requires that ArcMap is not in edit mode"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; ' Find the field named AF
&amp;nbsp; Dim pCalc As ICalculator
&amp;nbsp; Dim pField As IField
&amp;nbsp; Dim intFldIndex As Integer
&amp;nbsp; intFldIndex = pTable.FindField("AF")
&amp;nbsp; If intFldIndex = -1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "There must be a field named AF in the layer"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; ' Perform the calculation.
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Set pCalc = New Calculator
&amp;nbsp; Set pCursor = pTable.Update(Nothing, True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; With pCalc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set .Cursor = pCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Expression =
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 1 Then preExp = frmADTAdjustment.txtMon1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 2 Then preExp = frmADTAdjustment.txtTues1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 3 Then preExp = frmADTAdjustment.txtWed1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 4 Then preExp = frmADTAdjustment.txtThur1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EsleIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 5 Then preExp = frmADTAdjustment.txtFri1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Field = "AF"
&amp;nbsp;&amp;nbsp; End With
&amp;nbsp; pCalc.Calculate

&amp;nbsp; Exit Sub
EH:
&amp;nbsp;&amp;nbsp; 
&amp;nbsp; MsgBox Err.Number &amp;amp; "&amp;nbsp; " &amp;amp; Err.Description

End Sub&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; Thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-LostinKansas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jun 2010 14:57:59 GMT</pubDate>
    <dc:creator>JessicaKilpatrick</dc:creator>
    <dc:date>2010-06-28T14:57:59Z</dc:date>
    <item>
      <title>Field Calculator using input from a form in VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/field-calculator-using-input-from-a-form-in-vba/m-p/707599#M18928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a form for a user to input an adjustment factor table.&amp;nbsp; It allows the user to input a year for each month as well as the given adjustment factor, which is dependent on the day of the week in in that specific month. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it looks something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;January&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[year]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[mon]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[tues]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[wed]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[ect...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;February&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[year]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[mon]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[tues]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[wed]&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;[ect...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ect..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then at the bottom is a command button to store the entered values in the Adjustment table.(Which is a table that has two fields Date, which already stores all the individual days in the year, and Adjustment)&amp;nbsp; I want the command button at the bottom to run a field calculation checking the year and the day of week from the date field then using the correctly selected value entered in the form as the value for the Adjustment field. So really it is just an elaborate if then statement.&amp;nbsp; I just dont know how to make the field calculator look at the form for a value.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what i have already.&amp;nbsp; I know the syntax for the .Expression is wrong but i am not sure how to make it work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Private Sub cmdSave_Click()

&amp;nbsp; On Error GoTo EH
&amp;nbsp; 
&amp;nbsp; Dim pDoc As IMxDocument
&amp;nbsp; Set pDoc = ThisDocument

&amp;nbsp; 'set table to ADT_Adjustment&amp;nbsp; **must be the top table in the Table of Contents
&amp;nbsp; 
&amp;nbsp; Dim pTc As ITableCollection
&amp;nbsp; Set pTc = pDoc.FocusMap
&amp;nbsp; Dim pTable As ITable
&amp;nbsp; Set pTable = pTc.Table(0)
&amp;nbsp; 
&amp;nbsp; ' This calculation is to be done outside of an edit session.
&amp;nbsp; Dim pEditor As IEditor
&amp;nbsp; Dim pID As New UID
&amp;nbsp; pID = "esriCore.Editor"
&amp;nbsp; Set pEditor = Application.FindExtensionByCLSID(pID)
&amp;nbsp; If pEditor.EditState = esriStateEditing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "This requires that ArcMap is not in edit mode"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; ' Find the field named AF
&amp;nbsp; Dim pCalc As ICalculator
&amp;nbsp; Dim pField As IField
&amp;nbsp; Dim intFldIndex As Integer
&amp;nbsp; intFldIndex = pTable.FindField("AF")
&amp;nbsp; If intFldIndex = -1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "There must be a field named AF in the layer"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; ' Perform the calculation.
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Set pCalc = New Calculator
&amp;nbsp; Set pCursor = pTable.Update(Nothing, True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; With pCalc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set .Cursor = pCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Expression =
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 1 Then preExp = frmADTAdjustment.txtMon1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 2 Then preExp = frmADTAdjustment.txtTues1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 3 Then preExp = frmADTAdjustment.txtWed1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 4 Then preExp = frmADTAdjustment.txtThur1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EsleIf DatePart("yyyy", pTable.FindField("Date_Cnt")) = frmADTAdjustment.txtYearJAN.Text And DatePart("m", pTable.FindField("Date_Cnt")) = 1 And DatePart("w", pTable.FindField("Date_Cnt")) = 5 Then preExp = frmADTAdjustment.txtFri1.Text
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Field = "AF"
&amp;nbsp;&amp;nbsp; End With
&amp;nbsp; pCalc.Calculate

&amp;nbsp; Exit Sub
EH:
&amp;nbsp;&amp;nbsp; 
&amp;nbsp; MsgBox Err.Number &amp;amp; "&amp;nbsp; " &amp;amp; Err.Description

End Sub&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; Thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-LostinKansas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 14:57:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/field-calculator-using-input-from-a-form-in-vba/m-p/707599#M18928</guid>
      <dc:creator>JessicaKilpatrick</dc:creator>
      <dc:date>2010-06-28T14:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator using input from a form in VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/field-calculator-using-input-from-a-form-in-vba/m-p/707600#M18929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have come across a fix for my issue, I am not sure that it is the most efficient or effective way of solving the problem but it is working.&amp;nbsp; I had to move the form from the map document template to the Normal template because of how the field calculator was conducting the calculation.&amp;nbsp; I also changed my code for .Expression equal to a variable and then set .PreExpression to my criteria.&amp;nbsp; Hope this will help for anyone also having this issue.&amp;nbsp; However if there is a better way to go about this please don't hesitate to let me know.&amp;nbsp; Thanks.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what i changed the field calculator expression to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;With pCalc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set .Cursor = pCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Pre Expression for the Sundays in the month of July ONLY
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .PreExpression = "Dim adtfactor as double" &amp;amp; vbNewLine &amp;amp; _
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "If DatePart(""yyyy"", [Date_Cnt]) = frmADTAdjustment2.txtYearJUL.Text And DatePart(""m"", [Date_Cnt]) = 7 And DatePart(""w"", [Date_Cnt]) = 1 Then adtfactor = frmADTAdjustment2.txtSun7.Text"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Expression = "adtfactor"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Field = "AF"
&amp;nbsp;&amp;nbsp; End With
&amp;nbsp; pCalc.Calculate&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:43:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/field-calculator-using-input-from-a-form-in-vba/m-p/707600#M18929</guid>
      <dc:creator>JessicaKilpatrick</dc:creator>
      <dc:date>2021-12-12T05:43:47Z</dc:date>
    </item>
  </channel>
</rss>

