Calculate amount student owes after payment made

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • martin77
    New Member
    • May 2007
    • 1

    Calculate amount student owes after payment made

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



    Code:
    '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
  • JConsulting
    Recognized Expert Contributor
    • Apr 2007
    • 603

    #2
    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.Connectio n, rstPays As adodb.Recordset
    Set cnnTrip = Application.Cur rentProject.Con nection
    Set rstPays = New adodb.Recordset
    'open the recordset
    rstPays.Open Source:="paymen ts", ActiveConnectio n:=cnnTrip, _
    CursorType:=adO penForwardOnly, LockType:=adLoc kPessimistic
    '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").Val ue = rstPays.Fields( "paid").Val ue - strPayment
    'assign current date
    rstPays.Fields( "updated").Valu e = Date
    'save changes to record
    rstPays.Update
    'close the recordset
    rstPays.Close
    Set rstPays = Nothing 'disassociate object variable from object

    where is it failing?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      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.

      Comment

      Working...