troubleshooting Question

Need some VBA logic help

Avatar of Jim P.
Jim P.Flag for United States of America asked on
Microsoft AccessSQL
5 Comments1 Solution616 ViewsLast Modified:
I'm trying to work the logic out for this. I want my results to something like below. I'm trying to populate the SeqNum off a check if the prior Client_Id, last and first match.

Client_Id_Num   Last_Name    First_Name  SeqNum
00-1365         Smith        Alfred      1
00-1365         Smith        Alfred      2
00-1365         Smiths       Alfred      1
00-1412         Jones        Alan        1
00-1412         Jones        Alan        2
00-1412         Jones        Alan        3
00-1550         Doe          Jeff        1
00-1550         Doe          Mitzi       1
02-1036         (dtr)        Terri       1
02-1036         Thomas       Terry       1
02-1036         Pear         Stacy       1
02-1036         (dtr)        Stacy       1
02-3362         Lemon        Alfredo     1
02-3362         Lemon        Alfredo     2
02-3362         Lemon        Guadalupe   1
04-1005         Cherry       Omar        1
04-1005         Orange       Marisol     1
04-1005         Orange       Marisol     2
04-1126         Banana       Deborah     1
04-1126         Banana       Deborah     2
04-1126         Apple        Tristan     1
04-1126         Apple        Deborah     1

The logic I have so far:

ClientID = "0"
FName = "ZZ"
LName = "ZZ"

Do While RS.EOF = False
    If ClientID <> RS!Client_Id_Number Then
        I = 1
        With RS
            ClientID = !Client_Id_Number
            FName = !First_name
            LName = !Last_name
            .Edit
            !SeqNum = I
            .Update
        End With
    Else
        If LName <> RS!Last_name Then
            If FName <> RS!First_name Then
                I = 1
                With RS
                    ClientID = !Client_Id_Number
                    LName = !Last_name
                    FName = !First_name
                    .Edit
                    !SeqNum = I
                    .Update
                End With
            Else
                I = I + 1
                With RS
                    .Edit
                    !SeqNum = I
                    .Update
                End With
            End If
        Else
            I = 1
            With RS
                ClientID = !Client_Id_Number
                LName = !Last_name
                .Edit
                !SeqNum = I
                .Update
            End With

        End If
    End If

    RS.MoveNext

Loop

RS.Close

It's not giving me the right Sequence Number. On the Jeff and Mitzi doe, I'm getting a 1 and 2. On the Alfred Smith, I'm getting 1, 1, 2. It should be 1,2,1. I just can't get the logic down for this one.

Thanks all.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros