Connecting Tech Pros Worldwide Forums | Help | Site Map

Calculate amount student owes after payment made

Newbie
 
Join Date: May 2007
Posts: 1
#1: May 25 '07
Here is what I have for the code keep getting error on



Expand|Select|Wrap|Line Numbers
  1. 'declare variables and assign address to object variables
  2.     Dim strId As String, strPayment As String, curPayment As Currency
  3.     Dim cnnTrip As adodb.Connection, rstPays As adodb.Recordset
  4.     Set cnnTrip = Application.CurrentProject.Connection
  5.     Set rstPays = New adodb.Recordset
  6.     'open the recordset
  7.     rstPays.Open Source:="payments", ActiveConnection:=cnnTrip, _
  8.         CursorType:=adOpenForwardOnly, LockType:=adLockPessimistic
  9.     'enter student ID and amount paid, then convert amount paid to a number
  10.     strId = InputBox(prompt:="Enter ID:", title:="Student ID")
  11.     strPayment = InputBox(prompt:="Enter payment:", title:="Payment", Default:=0)
  12.     curPayment = Val(strPayment)
  13.     'search for ID in ID field, then update the record's Paid and Updated fields
  14.     rstPays.Find criteria:="id = '" & strId & "'"
  15.     'calculate total amount paid
  16.  rstPays.Fields("paid").Value = rstPays.Fields("paid").Value - strPayment 
  17.     'assign current date
  18.     rstPays.Fields("updated").Value = Date
  19.     'save changes to record
  20.     rstPays.Update
  21.     'close the recordset
  22.     rstPays.Close
  23.     Set rstPays = Nothing   'disassociate object variable from object

JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#2: May 26 '07

re: Calculate amount student owes after payment made


Quote:

Originally Posted by martin77

Here is what I have for the code keep getting error on



'declare variables and assign address to object variables
Dim strId As String, strPayment As String, curPayment As Currency
Dim cnnTrip As adodb.Connection, rstPays As adodb.Recordset
Set cnnTrip = Application.CurrentProject.Connection
Set rstPays = New adodb.Recordset
'open the recordset
rstPays.Open Source:="payments", ActiveConnection:=cnnTrip, _
CursorType:=adOpenForwardOnly, LockType:=adLockPessimistic
'enter student ID and amount paid, then convert amount paid to a number
strId = InputBox(prompt:="Enter ID:", title:="Student ID")
strPayment = InputBox(prompt:="Enter payment:", title:="Payment", Default:=0)
curPayment = Val(strPayment)
'search for ID in ID field, then update the record's Paid and Updated fields
rstPays.Find criteria:="id = '" & strId & "'"
'calculate total amount paid
rstPays.Fields("paid").Value = rstPays.Fields("paid").Value - strPayment
'assign current date
rstPays.Fields("updated").Value = Date
'save changes to record
rstPays.Update
'close the recordset
rstPays.Close
Set rstPays = Nothing 'disassociate object variable from object


where is it failing?
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: May 26 '07

re: Calculate amount student owes after payment made


This is not an acceptable question Martin. We are not a code debugging service!
We can help you by answering specific questions, or we can work with you a little to help you resolve your problems. We do not do the work for you, especially when you give no indication as to what (if anything) you've tried and had trouble with.

If you would like to explain what you're trying to do and where, in the code, your efforts are failing (Error Message etc) then we can consider providing you with some help.

MODERATOR.
Reply