Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Loan Schedule VBA
Ed B 

10 years ago
I am working on the loan amortization from your seminar. I have gotten to a roadblock. On the calculate button I have this VBA code as shown in the video.


Private Sub Command18_Click()
   If MsgBox("Are you Sure? This will erase all payment data and create a new payment schedule!", vbYesNoCancel) <> vbYes Then
End If
Exit Sub

    If IsNull(Forms!LoanF!PaymentAmount) Then
    MsgBox "You need to calculate the payment amount first"
End If
Exit Sub

    DoCmd.SetWarnings False

    DoCmd.RunSQL ("DELETE * FROM ScheduleT WHERE LoanID=" & Forms!LoanF!LoanId)
    Me.Requery
    DoCmd.GoToControl "PaymentNumber"
    Dim BBal As Currency
    Dim Counter As Long
    Dim Curdate As Date
    Dim x As Integer
    Dim TotalPrin As Currency, correction As Currency

    BBal = Forms!LoanF!LoanAmount
    Counter = 1
    Curdate = Forms!LoanF!StartDate

While BBal > 0
    DoCmd.GoToRecord , , acNewRec
    PaymentNumber = Counter
    Counter = Counter + 1
    DueDate = Curdate

Select Case Forms!LoanF!FrequencyID
    Case 1: Curdate = DateAdd("m", 12, Curdate) 'annual
    Case 2: Curdate = DateAdd("m", 6, Curdate) 'semi annual
    Case 3: Curdate = DateAdd("q", 1, Curdate) 'quartley
    Case 4: Curdate = DateAdd("m", 1, Curdate) 'monthly
    Case 5: 'semi monthly
If Day(Curdate) = 1 Then
   Curdate = Curdate + 14 'inc to 15th
Else '1st of next month
   Curdate = DateSerial(Year(Curdate), Month(Curdate) + 1, 1)
  End If
    Case 6: Curdate = DateAdd("m", 2, Curdate) 'bi monthly
    Case 7: Curdate = DateAdd("ww", 1, Curdate) 'weekly
    Case 8: Curdate = DateAdd("ww", 2, Curdate) 'bi weekly
  End Select
  
     AmountPaid = 0
     RegularPayment = 0
     ExtraPayment = 0
     BeginningBalance = BBal
     AmountDue = Forms!LoanF!PaymentAmount
     Interest = Round(BeginningBalance * (Forms!LoanF!InterestRate / Forms!LoanF!FrequencyID.Column(2)), 2)
     Principle = AmountDue - Interest
     If BBal < Forms!LoanF!PaymentAmount Then
     EndingBalance = 0
     TotalPrin = DSum("Principle", "scheduleT", "LoanId=" & Forms!LoanF!LoanId) + Principle
     correction = Forms!LoanF!LoanAmount - TotalPrin
     AmountDue = AmountDue + correction
     Principle = Principle + correction
  Else
   EndingBalance = BeginningBalance - Principle
End If
   BBal = EndingBalance
Wend
      Forms!LoanF.Requery
   DoCmd.SetWarnings True
   End If
  
End Sub


It failss to go beyond the messages at the top of the code. Any help is appreciated.


Reply from Alex Hedley:

i think you have the Exit Sub in the wrong way

Swap

End If
Exit Sub

To

Exit Sub
End If

They way you have it will always close after the first If condition.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/15/2026 7:53:38 AM. PLT: 1s