By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

Calculate amount student owes after payment made

P: 1
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
May 25 '07 #1
Share this Question
Share on Google+
2 Replies

JConsulting
Expert 100+
P: 603
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?
May 26 '07 #2

NeoPa
Expert Mod 15k+
P: 31,770
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.
May 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.