Results 1 to 3 of 3
  1. #1
    annux3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    8

    Finding value from a range and if not match then find next using data from found row

    Hello,

    I have a table that contains passive and active devices. I want to find correct active device to which passive device is connected. However passive device can be connected to another passive device and after that to an active device - could be endless times a passive device is connected to passive device and then in the end to an active device.

    I will include excel tables with data and wanted result.

    The criteria is i think something like this:

    TYPE IS D3P AND Mark DOES NOT CONTAIN "ZUUM" AND Sort IS "Passive"



    I got the result via doing excel function index-match for like 5 times and excel stalling.
    IN the previous thread i got to know that it probably is doable via VBA.

    Any ideas? or questions?

    Thank you,

    A.
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Here's some code...you may need to tweek it to match your table name. (mine is: TBL = "tDevices" )
    in vbe run : FineActiveDevice
    it will scan the table plotting the path to the active device.

    Code:
    Private Const kTBL = "tDevices"
    
    
    Public Sub FineActiveDevice()
    Dim rst
    Dim vID, vNext, vPrev, vName
    Dim vStatus
    Dim sSql As String
    
    
    sSql = "select * from " & kTBL & " ORDER BY [ID]"
    
    
    Set rst = CurrentDb.OpenRecordset(kTBL)
    With rst
       While Not .EOF
           vID = .Fields("ID").Value & ""
           vNext = .Fields("Device_ID").Value & ""
           vName = .Fields("Device").Value & ""
           vStatus = Left(.Fields("Sort").Value & "", 1)
           
           If vStatus <> "A" Then
              FindStatus vNext
           Else
              PostTrail vID, vName, vStatus, "--end"
           End If
           
           .MoveNext
       Wend
    End With
    Set rst = Nothing
    End Sub
    
    
    Public Sub FindStatus(ByVal pvID)
    Dim rst
    Dim vID, vNext, vPrev
    Dim vStatus
    Dim sSql As String
    
    
    On Error GoTo endIt
    sSql = "select * from " & kTBL & " where [ID]='" & pvID & "'"
    Set rst = CurrentDb.OpenRecordset(sSql)
    With rst
        vStatus = Left(.Fields("Sort").Value & "", 1)
        vName = .Fields("Device").Value & ""
        vNext = .Fields("Device_ID").Value & ""
        
        PostTrail pvID, vName, vStatus, vNext
        If vStatus = "A" Then
           PostTrail "", vName, vStatus, "--end"
        Else
           FindStatus vNext
        End If
    End With
    endIt:
    Set rst = Nothing
    End Sub
    
    
    Public Sub PostTrail(pvID, pvName, pvStatus, pvNext)
    'write to table
    sSql = "insert into table ([ID],["
    'or
    'write to debug window
    Debug.Print pvID, pvName, pvStatus, pvNext
    End Sub

  3. #3
    annux3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    8
    OK, it does something.

    As I understand then this code does not consider the criteria
    Code:
    SELECT * FROM tablename WHERE [TYPE] = "D3P" AND NOT [Mark] LIKE "*ZUUM*" AND [Sort] = "Passive"
    Can the output also include source device and found device?

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

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2015, 02:11 AM
  2. Replies: 14
    Last Post: 05-09-2013, 06:53 AM
  3. Trouble finding closest match
    By cutsygurl in forum SQL Server
    Replies: 1
    Last Post: 02-22-2013, 03:59 PM
  4. Replies: 8
    Last Post: 11-04-2011, 06:52 AM
  5. Finding data that doesn't match
    By dlhayes in forum Queries
    Replies: 1
    Last Post: 11-11-2006, 08:14 PM

Tags for this Thread

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