Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:58:23+00:00 2026-06-09T03:58:23+00:00

So, I inherited some code (below) from someone else and I’m trying to understand

  • 0

So, I inherited some code (below) from someone else and I’m trying to understand how it works. I understand msot of the code (though I’m pretty new to Access VBA) but the one part I don’t get is how this code groups all the info for one policy together.

The situation is as follows. To get premium data for a specific policy, from our company database, we have to get it one coverage per line. But, I want all premiums, one for each coverage, all on the same line. So, this code puts it all together from many lines into one line. For simplicity, I knocked it down to 3 total coverages, though there are many more. As I read the code, it seems to assume that all the info for one policy is together, like the 1, 2, or 3 rows for a specific policy are in order. But, even when I, for example, order the table by the premium (amount) column, it still gets all the premium for one policy on one line. I don’t see anywhere in the code that should make this work. The code is comparing the policy number on one line to the policy number on the next. If they are the same, group the premium together. If they are different, don’t. Again, I could order the table so that the records for one policy are not together, but the end result still comes out right. Am I missing something? Is it something in Access doing it? Thanks for any help!

Option Compare Database
Option Explicit

' Premium is imported with one row for each coverage per policy, so possibly several rows per policy.
' This procedure takes several rows per policy and makes them into one row.
Sub ScrubPremium()

Dim i As Long, j As Long, k As Long
Dim NumRecords As Long, found As Long, UniqueCount As Long
Dim tempPolicyNum As String, tempCoverage As String, tempPremium As Single
Dim PolicyNumArray() As String, PremiumArray() As Single, TotalPremiumArray() As Single

Dim db As DAO.Database
Set db = CurrentDb

Dim infile As Variant, outfile As Variant

Set infile = db.OpenRecordset("Imported Premium")
CurrentDb.Execute "DELETE * FROM [Finalized Premium]"
Set outfile = db.OpenRecordset("Finalized Premium")

NumRecords = infile.RecordCount
ReDim PolicyNumArray(NumRecords)
ReDim PremiumArray(NumRecords, 3)
ReDim TotalPremiumArray(NumRecords)

infile.MoveFirst

'initialize PremiumArray
For i = 1 To NumRecords
    For j = 1 To NumPremiums
        PremiumArray(i, j) = 0
    Next j
Next i

'populate arrays
UniqueCount = 0
For i = 1 To NumRecords
    tempPolicyNum = infile![Policy_Number]
    tempCoverage = infile![Coverage]
    tempPremium = infile![Premium]

    k = 0
    found = 0

    Do Until k = UniqueCount Or found = 1 'check for unique policy
        If tempPolicyNum = PolicyNumArray(k + 1) Then
            found = 1
        Else
            k = k + 1
        End If
    Loop

    If found = 0 Then
        UniqueCount = UniqueCount + 1
        PolicyNumArray(k + 1) = tempPolicyNum
    End If

    Select Case tempCoverage
    Case "Comprehensive"
        j = 1
    Case "Collision"
        j = 2
    Case Else
        j = 3
    End Select
    PremiumArray(k + 1, j) = PremiumArray(k + 1, j) + tempPremium
    TotalPremiumArray(k + 1) = TotalPremiumArray(k + 1) + tempPremium
    infile.MoveNext
Next i

'Populate table
For i = 1 To UniqueCount
    outfile.AddNew
        outfile![Full Policy Number] = PolicyNumArray(i)

        outfile![Comp Premium] = PremiumArray(i, 1)
        outfile![Coll Premium] = PremiumArray(i, 2)
        outfile![Other Premium] = PremiumArray(i, 3)
        outfile![Total Premium] = TotalPremiumArray(i)
    outfile.Update
Next i

infile.Close
outfile.Close

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:58:24+00:00Added an answer on June 9, 2026 at 3:58 am

    The code is comparing the policy number on one line to the policy
    number on the next. If they are the same, group the premium together.
    If they are different, don’t.

    Almost.

    There are two loops here. One walks through each row of your input file. On each row of the input file, a second loop walks through (potentially all of) PolicyNumArray, looking for policy numbers that match the number taken from the input file.

    If I were you, I’d step through this with the debugger. Make sure it’s doing what you expect it to do. I’d want to look closely at this part (some lines snipped).

    UniqueCount = 0
    For i = 1 To NumRecords
        k = 0
        Do Until k = UniqueCount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've in inherited some code that I'm trying to understand and any searching I
I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I have inherited some code (from zip file) from a developer and git initialzed,
I have some ASP code that I've inherited from my predecessor (no, it's not
I have inherited some Silverlight\WCF code and now need to implement some new features.
Ive inherited some code which started out as an Android project but really is
I've inherited some code on a system that I didn't setup, and I'm running
I've inherited some code which breaks a page up into tabs using divs. On
I'm not sure what the problem is here, I've inherited some code form Zend
I have inherited some HTML code and have been asked to align the two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.