I need to display the Monthly Payment by selecting a Month combo box satisfying condition of Financial Year and Section code (office code)

sbaud2003

Member
Local time
Today, 08:50
Joined
Apr 5, 2020
Messages
186
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
 
Well, your recordset is likely empty and these lines would cause an error in that event (and aren't necessary anyway):

rs.MoveLast
rs.MoveFirst

Also, you need to concatenate the last variable as you did the others.
 
Good point plog, I didn't pay attention to what the code was doing.
 

Users who are viewing this thread

Back
Top Bottom