I am using the code below: getting error (3021) no current record"
Click event:
Dim sql5, Sum
Dim FIN, CODE As Long
Dim MAS As String
FIN = Me.COMFY.value ' NUMBER
CODE = Me.TXTUC.value 'NUMBER
MAS = Me.CMPM.value 'TEXT
Dim rs As DAO.Recordset
sql5 = "SELECT * FROM [TOTAL CMP] WHERE ([section] = " & CODE & " and [finyear] = " & FIN & " and [mnth] = 'MAS' );"
Set rs = CurrentDb.OpenRecordset(sql5)
rs.MoveLast
rs.MoveFirst
While Not rs.EOF
Sum = Sum + rs("chamt")
rs.MoveNext
Wend
Me.TCMPM = Sum
end sub
'''''''
TCMPM is a text box which will display the result
chamt is the field name of amount in the "TOTAL CMP" query
Click event:
Dim sql5, Sum
Dim FIN, CODE As Long
Dim MAS As String
FIN = Me.COMFY.value ' NUMBER
CODE = Me.TXTUC.value 'NUMBER
MAS = Me.CMPM.value 'TEXT
Dim rs As DAO.Recordset
sql5 = "SELECT * FROM [TOTAL CMP] WHERE ([section] = " & CODE & " and [finyear] = " & FIN & " and [mnth] = 'MAS' );"
Set rs = CurrentDb.OpenRecordset(sql5)
rs.MoveLast
rs.MoveFirst
While Not rs.EOF
Sum = Sum + rs("chamt")
rs.MoveNext
Wend
Me.TCMPM = Sum
end sub
'''''''
TCMPM is a text box which will display the result
chamt is the field name of amount in the "TOTAL CMP" query