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

sbaud2003

Member
Local time
Today, 07:38
Joined
Apr 5, 2020
Messages
96
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
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:08
Joined
Aug 30, 2003
Messages
34,827
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:08
Joined
Aug 30, 2003
Messages
34,827
Good point plog, I didn't pay attention to what the code was doing.
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:08
Joined
Sep 21, 2011
Messages
7,500

Users who are viewing this thread

Top Bottom