Results 1 to 3 of 3
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    Referenceing a fleld in a lookup table to pull data from that row

    I am trying in VBA to reference a table for data to compare to another table. I think the issue is that I am only checking 1 row in the lookup table. How do I get it to do a lookup until found, or until end of file? If no data then [NN] = 0 or null.

    I am getting confused on the Do While Loop I guess.

    Thanks

    Code:
    Private Sub SINCTest_Click()
    Dim Uname As Variant
    Dim I As Integer, Z As Integer
    Dim NewWave As String, BDEs As String, Base As String, DIV As String, NN As String
    
    Set rU = CurrentDb.OpenRecordset("NBOI") ' Main table
    Set rN = CurrentDb.OpenRecordset("New_Net_ID") ' Lookup table
    
        V = " VHF"
        BDEs = "2BCT1ID"
        DIV = "1ID "
        
    If rU.BOF And rU.EOF Then
                    rU.Close          
                Else
                  rU.MoveLast
                  rU.MoveFirst
        Do While Not rU.EOF
                rU.Edit
    
        If rU![BN (Owning)] <> rU![BN (Operating)] Then
                BN = rU![BN (Operating)]
        ElseIf rU![BN (Owning)] = rU![BN (Operating)] Then
                BN = rU![BN (Owning)]
                Else: BN = ""
        End If
                
              Uname = BN
                
                Select Case BN
                    Case Is = "BDE"
                        Base = BDEs
                        Z = 1
                    Case Is = "DIV"
                        Base = DIV
                        Z = 0
                    Case Else
                        Base = ""
                End Select
    
    For I = 1 To 6
    
            If rU("SINCGARS  " & I) = rN("NBOI_NET") Then
                    NN = rN("NETID")
            End If
       
        If rU("SINCGARS  " & I) = "METT" Then
                  rU("SINC" & I) = "12500-METT-T" & V
        ElseIf rU("SINCGARS  " & I) Like "Div*" Then
                  rU("SINC" & I) = NN & "-" & DIV & Right(rU("SINCGARS  " & I), 3) & V
        
        ElseIf rU("SINCGARS  " & I) Like "Bde*" Then
            NewWave = Base & Right(rU("SINCGARS  " & I), (Len(rU("SINCGARS  " & I)) - 3))
                rU("SINC" & I) = NN & "-" & NewWave & V
        
       ElseIf IsNull(rU("SINCGARS  " & I)) Or rU("SINCGARS  " & I) = "" Then
                  rU("SINC" & I) = ""
             End If
        End If
    Next I
    
                rU.Update
                rU.MoveNext
    
        Loop
    
    End If
    
           rU.Close
    
           Set rU = Nothing
          Set rN = Nothing
    
    End Sub


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    there NO need for any of this code. This is what queries are for.
    The query will do this for you, and 100 times faster.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    This is only a portion of the code that is relevant to the question. I do see your point.

    Example: Sported unit. This is a no specific and requires looking at a different control in that row to determine what unit is supported, then you need to find the unit name and the specific net from the table that designates the supported unit. The same would go for Medics assigned to one place but are signed out to support a subordinate unit.

    Another example: Depending on the unit the plt referenced may have a name, but is assigned a number for the ID:


    Crawl = 1
    Walk = 2
    Run = 3

    I would have to make a column for each radio [SINCGARS 1] through [SINCGARS 6]:

    A start and it needs to have PLTs added

    SINC2a: IIf([SINCGARS 2]="CO CMD",[NetID] & "-" & [CO (Operating)] & " " & [Base] & " VHF",IIf([SINCGARS 2]=[NBOI_Net],[NetID] & "-" & [Netname] & " VHF",[SINC2]))

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query pull data from another table
    By tareyj8569 in forum Queries
    Replies: 6
    Last Post: 08-23-2015, 10:43 AM
  2. Replies: 1
    Last Post: 06-12-2015, 02:02 PM
  3. Trying to pull data from table into VBA code
    By kcrty in forum Programming
    Replies: 8
    Last Post: 04-08-2015, 06:37 PM
  4. Pull Data from another table
    By bbranco in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:15 AM
  5. pull up data from a table into a form
    By MattD00 in forum Forms
    Replies: 1
    Last Post: 03-30-2011, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums