Any input is welcome. The situation is users were allowed to put the amount of pesticide applied (Active) along with the 1-3 crops it was applied to (Crop_Code1,2,3) in a single record. I wanted to divide the Active value by 2 if used on 2 crops, and divide the Active by 3 if 3 crops, and eventually create separate records using a Union command.
Running the following code, I first a box asking for a Parameter Value for CropActive1, then an error message saying "Field not updatable." Can anyone help me get beyond the error messages? Much thanks in advance.
Function DoCropConversion()
Const table As String = "[MainTable]"
'make sure CropActive columns are created before running
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active] where [Crop_Code2]=0"
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active]* 0.5 where [Crop_Code2]>0 and [Crop_Code3]=0"
DoCmd.RunSQL "update " & table & " set [CropActive2] = [Active]* 0.5 where [Crop_Code2]>0 and [Crop_Code3]=0"
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active]* 0.333 where [Crop_Code3]>0"
DoCmd.RunSQL "update " & table & " set [CropActive2] = [Active]* 0.333 where [Crop_Code3]>0"
DoCmd.RunSQL "update " & table & " set [CropActive3] = [Active]* 0.333 where [Crop_Code3]>0"
End Function
Running the following code, I first a box asking for a Parameter Value for CropActive1, then an error message saying "Field not updatable." Can anyone help me get beyond the error messages? Much thanks in advance.
Function DoCropConversion()
Const table As String = "[MainTable]"
'make sure CropActive columns are created before running
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active] where [Crop_Code2]=0"
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active]* 0.5 where [Crop_Code2]>0 and [Crop_Code3]=0"
DoCmd.RunSQL "update " & table & " set [CropActive2] = [Active]* 0.5 where [Crop_Code2]>0 and [Crop_Code3]=0"
DoCmd.RunSQL "update " & table & " set [CropActive1] = [Active]* 0.333 where [Crop_Code3]>0"
DoCmd.RunSQL "update " & table & " set [CropActive2] = [Active]* 0.333 where [Crop_Code3]>0"
DoCmd.RunSQL "update " & table & " set [CropActive3] = [Active]* 0.333 where [Crop_Code3]>0"
End Function