Hi All,
I am a novice in MS Access and VBA. I have written this code below to get a cumulative sum when a certain condition is satisfied. Calling this function in a Access query design. But it throws an error saying it contains a syntax error. Could anyone help rectify this?
Public Function TotalFx(CASE_ID As String, ELM_ID As Integer) As Double
Dim rs As Recordset
Dim TotalFx As Double
Set rs = CurrentDb.OpenRecordset("SELECT [Fx S] FROM [Query_Loads_Sum_6] WHERE [CASE_ID] = '" & CASE_ID & "' AND [ELM_ID] < " & ELM_ID)
Do While Not rs.EOF
TotalFx = TotalFx + rs("[Fx S]")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
TotalFx = TotalFx
End Function
I am a novice in MS Access and VBA. I have written this code below to get a cumulative sum when a certain condition is satisfied. Calling this function in a Access query design. But it throws an error saying it contains a syntax error. Could anyone help rectify this?
Public Function TotalFx(CASE_ID As String, ELM_ID As Integer) As Double
Dim rs As Recordset
Dim TotalFx As Double
Set rs = CurrentDb.OpenRecordset("SELECT [Fx S] FROM [Query_Loads_Sum_6] WHERE [CASE_ID] = '" & CASE_ID & "' AND [ELM_ID] < " & ELM_ID)
Do While Not rs.EOF
TotalFx = TotalFx + rs("[Fx S]")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
TotalFx = TotalFx
End Function