Dear All,
I tried to run a variable to accumulate the value for the same country, but it prompts me that it is over flow. I have try to round() the value within the query or in the VBA, but fails.
Please help how I can solve the problem. Below are the coding, highlighting is the error.
********************************************************
Set query = CurrentDb.OpenRecordset("qry_ABC_Country_ByValue")
CumTotDemand = 0
query.MoveFirst
OldCountry = " "
Do Until query.EOF = True
'Reset Cumulative Total Demand for new country
If OldCountry <> query![Country] Then
CumTotDemand = 0
End If
'Always accumulate Total Demand for same country
CumTotDemand = query![ValueRatio] + CumTotDemand
'Update the table with [Article Value], [Country Value],
'[Value Ratio], [Accumulated Ratio]
'Key: Country Article
updSql = "UPDATE ABC_Country SET " & _
"ABC_Country.Article_Value = " & query![articlevalue] & ", " & _
"ABC_Country.Country_Value = " & query![CountryTotalValue] & ", " & _
"ABC_Country.Value_Ratio = " & query![ValueRatio] & ", " & _
"ABC_Country.CumulativeValue = " & CumTotDemand & _
" WHERE ABC_Country.[WE - Country] = '" & query![Country] & "' " & _
" AND ABC_Country.[Material] = '" & query![Article] & "' "
dbs.Execute updSql
OldCountry = query![Country]
query.MoveNext
Loop
query.Close
********************************************************
I tried to run a variable to accumulate the value for the same country, but it prompts me that it is over flow. I have try to round() the value within the query or in the VBA, but fails.
Please help how I can solve the problem. Below are the coding, highlighting is the error.
********************************************************
Set query = CurrentDb.OpenRecordset("qry_ABC_Country_ByValue")
CumTotDemand = 0
query.MoveFirst
OldCountry = " "
Do Until query.EOF = True
'Reset Cumulative Total Demand for new country
If OldCountry <> query![Country] Then
CumTotDemand = 0
End If
'Always accumulate Total Demand for same country
CumTotDemand = query![ValueRatio] + CumTotDemand
'Update the table with [Article Value], [Country Value],
'[Value Ratio], [Accumulated Ratio]
'Key: Country Article
updSql = "UPDATE ABC_Country SET " & _
"ABC_Country.Article_Value = " & query![articlevalue] & ", " & _
"ABC_Country.Country_Value = " & query![CountryTotalValue] & ", " & _
"ABC_Country.Value_Ratio = " & query![ValueRatio] & ", " & _
"ABC_Country.CumulativeValue = " & CumTotDemand & _
" WHERE ABC_Country.[WE - Country] = '" & query![Country] & "' " & _
" AND ABC_Country.[Material] = '" & query![Article] & "' "
dbs.Execute updSql
OldCountry = query![Country]
query.MoveNext
Loop
query.Close
********************************************************