Using VBA in field calculator I am trying to figure out the expression that if 3 conditions are met populate a field using another field's value and I cant get it to work! CALC_CLASS is a joined table and SPEED LIMIT is a Double type, MMS_TEMP is text.

enter image description here

I am using VBA and ARC 10.3

if [SPEED_LIMIT]=>91 and [SPEED_LIMIT] <= 100 and [MMS_TEMP]="53,000 or more" then

elseif [SPEED_LIMIT]=>51 and [SPEED_LIMIT] <= 60 and [MMS_TEMP]="53,000 or more" then 


end if**                
  • Your greater than or equal => is incorrect. It should be >=.
    – ahmadhanb
    Jul 10, 2018 at 1:26

2 Answers 2


I think what is happening here is that you have entered all your worflow in the pre-logic script and then told the calculator that RD_BASELINE.CLASS_MMS=RD_BASELINE.CLASS_MMS, which doesn't mean anything. This pre-logic script is run BEFORE the operation takes place. To make this work, you need to define a function in the pre-logic script code, and then call that function using the expression. I don't code much in VB, but in python, I would try:

def calculate_answer(speed_limit, mms_temp, psl_91_100, psl_51_60, psl_1_40):
    if speed_limit >= 91 and speed_limit <= 100 and mms_temp == "53,000 or more":
        out = psl_91_100
    elif speed_limit >= 51 and speed_limit <= 60 and mms_temp =="53,000 or more":
        out = psl_51_60
        out = psl_1_40 
    return out

Then, in the expression field, just enter:

calculate_answer([SPEED_LIMIT], [MMS_TEMP], [CALC_CLASS_MMS.PSL_91_100],  [CALC_CLASS_MMS.PSL_51_60], [CALC_CLASS_MMS.PSL_1_40])

You can find lots VB examples for the field calculator here if you want to stick to that language.

  • Your greater than or equal => is incorrect. It should be >=.
    – ahmadhanb
    Jul 10, 2018 at 1:29

I am going to provide you an answer in Python:

open your Field Calculator and activate your show Codeblock:

enter image description here

Do not care about the field names since I am using a personal table. You can see the code in the picture but since last line is not showing I paste the code here:

def compare (SpeedLmt, MMS_Temp, AssignValue):
    if (SpeedLmt >= 92 and SpeedLmt <= 100  and MMS_Temp == 53000):
        return = "psl_91_100"
    elif (SpeedLmt >= 51 and SpeedLmt <= 60 and MMS_Temp == 53000):
        AssignValue = "psl_51_60"
        AssignValue = "AssignValue"

Then call the function in the AssignValu:

compare ( !SpeedLimit! , !MM_TEMP!, !AssignValu! )

  • Thanks Milad, However will the "psl_1_40" update via the values in the field or just simply add in psl_1_40 (text) into the MMS field? Jul 9, 2018 at 17:13
  • It will add in "psl_1_40" if the two above conditions are not met. If you want to have more control (like assigning a certain value) based on a certain condition then we need to add another statement. Did I answer your question?
    – Milad
    Jul 9, 2018 at 17:18
  • No Milad but thank you I am still looking for "update another field using another field's values" not simply assigning a text value. Jul 9, 2018 at 17:27
  • I am assuming that you have created a field for psl_ so before applying the code there is nothing in that column. If you have already values for psl_ and you want to keep the ones non affected by the code you need to replace "psl_1_40" with the name of your variable so the code will return the same pre-stored value without changing it. Did I answer your question?
    – Milad
    Jul 9, 2018 at 17:29
  • I updated the last line: AssignValue = "AssignValue" so you will get the pre-stored value.
    – Milad
    Jul 9, 2018 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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