?
Solved

help with loop

Posted on 2004-03-22
1
Medium Priority
?
189 Views
Last Modified: 2010-05-01
I wrote this code to pull the first borr_nrb which (is 1). And the first instance of  brr-nbr (one). Once it is found I want it to fine borr_nbr (2) and give me the first instance of borr_nbr 2. I need help is setting up the loop or counter.
Thanks

Dim Result
Dim intIndex As integer
Dim strAddr As string

For intIndex = 1 To Val(CDE.LT-ADDRESS.BORR-ADDR("Count"))
      If Val(CDE.LT-ADDRESS.BORR-NBR(intIndex)) = vElementIndex Then
            strAddr = Trim(CDE.LT-ADDRESS.BORR-ADDR(intIndex))
            If Trim(CDE.LT-ADDRESS.BORR-ADDR2(intIndex)) <> "" Then
                  strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-ADDR2(intIndex))
            End If
            If CDE.LT-ADDRESS.MILIT-FLAG(intIndex) = True Then
                  If Trim(CDE.LT-ADDRESS.MILIT-ADDR(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.MILIT-ADDR(intIndex))
                  End If
            Else
                  If Trim(CDE.LT-ADDRESS.BORR-CITY(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-CITY(intIndex))
                  End If
                  If Trim(CDE.LT-ADDRESS.BORR-ST(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-ST(intIndex))
                  End If
                  If Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)) <> "" Then
                        strAddr = strAddr & "  "
                        If Len(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex))) = 9 Then
                              strAddr = strAddr & LEFT(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)), 5) & "-"
                              strAddr = strAddr & RIGHT(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)), 4)
                        Else
                              strAddr = strAddr & Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex))
                        End If
                  End If
            End If
            Exit For
      End If
Next
0
Comment
Question by:cdb424ttm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 10651928
I'm guessing that this is what you want.


Dim Result
Dim intIndex As Integer
Dim strAddr As String
Dim vElementIndex As Integer

For vElementIndex = 1 To 2
    For intIndex = 1 To Val(CDE.LT - ADDRESS.BORR - ADDR("Count"))
         If Val(CDE.LT - ADDRESS.BORR - NBR(intIndex)) = vElementIndex Then
              strAddr = Trim(CDE.LT - ADDRESS.BORR - ADDR(intIndex))
              If Trim(CDE.LT - ADDRESS.BORR - ADDR2(intIndex)) <> "" Then
                   strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - ADDR2(intIndex))
              End If
              If CDE.LT - ADDRESS.MILIT - FLAG(intIndex) = True Then
                   If Trim(CDE.LT - ADDRESS.MILIT - ADDR(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.MILIT - ADDR(intIndex))
                   End If
              Else
                   If Trim(CDE.LT - ADDRESS.BORR - CITY(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - CITY(intIndex))
                   End If
                   If Trim(CDE.LT - ADDRESS.BORR - ST(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - ST(intIndex))
                   End If
                   If Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)) <> "" Then
                        strAddr = strAddr & "  "
                        If Len(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex))) = 9 Then
                             strAddr = strAddr & Left(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)), 5) & "-"
                             strAddr = strAddr & Right(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)), 4)
                        Else
                             strAddr = strAddr & Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex))
                        End If
                   End If
              End If
              Exit For
         End If
    Next
Next vElementIndex
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question