Question : Populate Table from Multiple Calculated Field on a Form in Access

I'm trying to update multiple fields in a table with a calculated field on a form. The fields all belong to one recored identified by an estimate auto number called EstNum.   I know this is not generally a good idea, but I need to do this.  The table IS bound to the form.  I have successfully been able to update one field, but not multiple fields for some reason.  I'm using the following code (the code is not broken into multiple lines in my code):

DoCmd.RunCommand acCmdSaveRecord
 Dim StrSQL As String
    StrSQL = "update [tblEst] set [PrCostQty1] = " & [prCostQty1] & "   where [EstNum] = " & [EstNum] & ";"
    DoCmd.SetWarnings False
    DoCmd.RunSQL StrSQL
    DoCmd.SetWarnings True

which works well for the one field specified.  I'm trying to add multiple fields to the SQL Statement.  When I add the following code, I get nothing in any fields.

DoCmd.RunCommand acCmdSaveRecord
 Dim StrSQL As String
    StrSQL = "update [tblEst] set [PrCostQty1] = " & [prCostQty1] & " and [PrCostQty2] = " & [prCostQty2] &   where [EstNum] = " & [EstNum] & ";"
    DoCmd.SetWarnings False
    DoCmd.RunSQL StrSQL
    DoCmd.SetWarnings True
 

When I add the second field to the code,I get the "Missing Operator" error message using this code.   I also get no results in either field 1 or field 2. I do not understand why this does not work.  Thanks!

Answer : Populate Table from Multiple Calculated Field on a Form in Access

In terms of syntax then you do..

StrSQL = "update [tblEst] set [PrCostQty1] = " & [prCostQty1] & " , [PrCostQty2] = " & [prCostQty2] &   " where [EstNum] = " & [EstNum]

However this statement makes no sense to me as you appear to be trying to set something to itself.
Or is the [prCostQty1] within the quotes somehow different to the [prCostQty1] that is outside the quotes?
Random Solutions  
 
programming4us programming4us