+ Reply to Thread
Results 1 to 6 of 6

Compare rows in access table

Hybrid View

  1. #1
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Compare rows in access table

    Hi,

    I have a access table which contains few rows.
    I need to compare each row in the table with other rows in the same sheet.

    Key	Unit	Assembly   	Effective_Date
    10	05100070	6666666H92	05/02/2012
    10	05100070		         10/02/2012
    20	05100070	6666666H93	15/01/2013
    30	05100070	9999999H92	20/02/2012
    30	05100070		         25/02/2012
    40	05100070	9999999H93	30/01/2013
    50	05100070	7777777H92	05/02/2012
    50	05100070		         10/02/2012
    60	05100070	7777777H93	15/01/2013
    70	05100070	5555555H92	20/02/2012
    70	05100070		         25/02/2012
    80	05100070	5555555H93	30/01/2013
    Logic:
    If column "Key" contains different data in 2 rows then check column "Unit", If column "Unit" contains same data then check "Assembly",
    If column "Assembly" in one row is empty and column "Assembly" in another row has data then copy the value of column "Effective_Date" (column "Assembly" has value) to column "Effective_Date" of the row which is empty in column "Assembly".

    required output:
    Key	Unit	Assembly	         Effective_Date
    10	05100070	6666666H92	05/02/2012
    10	05100070		         15/01/2013
    20	05100070	6666666H93	15/01/2013
    30	05100070	9999999H92	20/02/2012
    30	05100070		         30/01/2013
    40	05100070	9999999H93	30/01/2013
    50	05100070	7777777H92	05/02/2012
    50	05100070		         15/01/2013
    60	05100070	7777777H93	15/01/2013
    70	05100070	5555555H92	20/02/2012
    70	05100070		         30/01/2013
    80	05100070	5555555H93	30/01/2013
    Thanks in advance.
    VIjay

    If you find any of the post useful to your question, please add to the contributor's reputation by clicking the blue scales icon in the blue bar of the post.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare rows in access table

    Any reason why you have posted the same question in the excel subforum and access?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Compare rows in access table

    Yes.

    Currently I have the excel file.
    In the later stage, the original excel file(without applying this logic) will be linked to access database and the same logic should be done in access.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Compare rows in access table

    Crossposted: http://www.mrexcel.com/forum/microso...ess-table.html

    I'm afraid your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Compare rows in access table

    I have posted the same question at
    http://www.mrexcel.com/forum/microso...ess-table.html

    Thanks.

  6. #6
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Compare rows in access table

    I have written this code to update the table, runs with no errors, debuged to check if the values are assigned correctly, but the table is not updated.
    Think I have missed something in the code to update.

    here is my code:
    Option Compare Database
    
    Private Sub Populate_Test_Table()
    'Dim rs As New ADODB.Recordset
    Dim A0 As String
    Dim B0 As String
    Dim C0 As String
    Dim D0 As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT * from test", dbOpenDynaset)
    
    Set Recordset = rs
    'rs.Open "SELECT A,B,C,D from test"
    
    A0 = ""
    B0 = ""
    C0 = ""
    D0 = ""
    While Not rs.EOF
    
    If rs!Key <> A0 And rs!Unit = B0 And (rs!assembly <> C0) Then
    rs.Edit
     D0 = rs!Effective_Date
    rs.Update
    End If
     A0 = rs!Key
     B0 = rs!Unit
     If rs!assembly <> "" Then
     
      C0 = rs!assembly
      Else
      rs.Edit
      rs!assembly = ""
      C0 = rs!assembly
      End If
      D0 = rs!Effective_Date
    rs.MoveNext
    Wend
    
    rs.Close
    Set rs = Nothing
    End Sub
    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1