473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Duplicate in particular row

Iam using the below code to search the duplicate records in Ms Excel before uploading to Ms access.

It is working fine but i want the msgbox to display that there is a duplicate record in perticular row.

Kindly help how to mention the same

Ananth
------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Set rst = DB.OpenRecordset("Claim_Status", dbOpenDynaset)
  2.  
  3. myRow = ActiveCell.Row
  4.  
  5. If rst.RecordCount <> 0 Then
  6. rst.FindFirst "StrInward_No = '" & RANGE("A2") & "'"
  7. If Not rst.NoMatch Then
  8.  
  9. R = 2
  10. Do While Len(RANGE("A" & R).Formula) > 0
  11. R = R + 1 ' next row
  12. Loop
  13.  
  14. MsgBox "Duplicate records found in" & myRow
  15.  
  16. ActiveWorkbook.Close
  17. rst.Close
  18.  
  19. Set rst = Nothing
  20. Set DB = Nothing
  21.  
  22. Exit Sub
  23. End If
  24. End If
Sep 1 '08 #1
3 1552
MikeTheBike
639 Expert 512MB
Hi

There seems to be an anomily in the code as there is no way you can find a duplicate as it stands. Without knowing anything about what you are trying to do, I suggest this, pehaps, may be what you want??
Expand|Select|Wrap|Line Numbers
  1. Set rst = Db.OpenRecordset("Claim_Status", dbOpenDynaset)
  2.  
  3. myrow = 0 'set row value
  4.  
  5. If rst.RecordCount <> 0 Then
  6.     rst.FindFirst "StrInward_No = '" & Range("A2") & "'"
  7.     If Not rst.NoMatch Then
  8.  
  9.         R = 3 ' start on next line to original search !!
  10.         Do While Len(Range("A" & R).Formula) > 0
  11.             If Range("A" & R) = rst("StrInward_No") Then 'compare cell with record found ??
  12.                 myrow = R 'if found set row value
  13.                 Exit Do ' and exit do (job done)!
  14.             End If
  15.             R = R + 1  'next row
  16.         Loop
  17.  
  18.         If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & R ' ouput row if found.
  19.  
  20.         ActiveWorkbook.Close
  21.         rst.Close
  22.  
  23.         Set rst = Nothing
  24.         Set Db = Nothing
  25.  
  26.         Exit Sub
  27.     End If
  28.  
  29.     Set rst = Nothing ' ??
  30.     Set Db = Nothing ' ??
  31. End If
HTH


MTB
Sep 1 '08 #2
Hi

There seems to be an anomily in the code as there is no way you can find a duplicate as it stands. Without knowing anything about what you are trying to do, I suggest this, pehaps, may be what you want??
Expand|Select|Wrap|Line Numbers
  1. Set rst = Db.OpenRecordset("Claim_Status", dbOpenDynaset)
  2.  
  3. myrow = 0 'set row value
  4.  
  5. If rst.RecordCount <> 0 Then
  6.     rst.FindFirst "StrInward_No = '" & Range("A2") & "'"
  7.     If Not rst.NoMatch Then
  8.  
  9.         R = 3 ' start on next line to original search !!
  10.         Do While Len(Range("A" & R).Formula) > 0
  11.             If Range("A" & R) = rst("StrInward_No") Then 'compare cell with record found ??
  12.                 myrow = R 'if found set row value
  13.                 Exit Do ' and exit do (job done)!
  14.             End If
  15.             R = R + 1  'next row
  16.         Loop
  17.  
  18.         If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & R ' ouput row if found.
  19.  
  20.         ActiveWorkbook.Close
  21.         rst.Close
  22.  
  23.         Set rst = Nothing
  24.         Set Db = Nothing
  25.  
  26.         Exit Sub
  27.     End If
  28.  
  29.     Set rst = Nothing ' ??
  30.     Set Db = Nothing ' ??
  31. End If
HTH


MTB
I am a beginer in MS Access. As per ur code as below it is showing blank row as duplicate. i am uploading a excel sheet contains StrInward_No's as 1 2 3 4 in 4rows but the code is showing as row 5 contains duplicate. kindly help.

Set rst = DB.OpenRecordset("Claim_Status", dbOpenDynaset)
myrow = ActiveCell.Row

If rst.RecordCount <> 0 Then
R = 2 ' start on next line to original search !!
Do While Len(RANGE("A" & R).Formula) > 0
If RANGE("A" & R) = rst("StrInward_No") Then 'compare cell with record found ??
myrow = R 'if found set row value
Exit Do ' and exit do (job done)!
End If
R = R + 1 'next row
Loop

If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & R ' ouput row if found.

'MsgBox "Duplicate records found in" & myrow

ActiveWorkbook.Close
rst.Close

Set rst = Nothing
Set DB = Nothing

Exit Sub
End If
Sep 2 '08 #3
MikeTheBike
639 Expert 512MB
I am a beginer in MS Access. As per ur code as below it is showing blank row as duplicate. i am uploading a excel sheet contains StrInward_No's as 1 2 3 4 in 4rows but the code is showing as row 5 contains duplicate. kindly help.

Set rst = DB.OpenRecordset("Claim_Status", dbOpenDynaset)
myrow = ActiveCell.Row

If rst.RecordCount <> 0 Then
R = 2 ' start on next line to original search !!
Do While Len(RANGE("A" & R).Formula) > 0
If RANGE("A" & R) = rst("StrInward_No") Then 'compare cell with record found ??
myrow = R 'if found set row value
Exit Do ' and exit do (job done)!
End If
R = R + 1 'next row
Loop

If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & R ' ouput row if found.

'MsgBox "Duplicate records found in" & myrow

ActiveWorkbook.Close
rst.Close

Set rst = Nothing
Set DB = Nothing

Exit Sub
End If
Hi

Small floor in my code this

If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & R

should have been this

If myrow <> 0 Then MsgBox "Duplicate records found in ROW " & myrow

That is the penalty of air code !

But apart from that

1) I cannot down load files (IT policy prevents this).

2) You seem to have missed the lines

rst.FindFirst "StrInward_No = '" & RANGE("A1") & "'"
If not rst.NoMatch Then


End If

etc

3) lines with 1, 2, 3, 4 in do not duplicate any data ??

4) I still think you should initialise myrow = 0 at the start of the code (what is the Active Cell at this time) !!??

BTW if the field StrInward_No is numeric then this

rst.FindFirst "StrInward_No = '" & RANGE("A1") & "'"

should be

rst.FindFirst "StrInward_No = " & RANGE("A1")


MTB
Sep 2 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
5
by: Steve B. | last post by:
A particular column in my Access DB table, and the associated datagrid, cannot have duplicate string entries. I've selected "Yes (no duplicates)" for the Indexed Field Property of this column in...
2
by: Brad Allison | last post by:
I have created a short routine to read certain data from an AS400 and put it into a small table stored in Access (I know not the best data store, but it is what we have for now). Anyway, some of...
4
by: skalra3 | last post by:
Hi, I just want to know that is there any way by sql that we can extract duplicate records from the name field in a particular table suppose table1 and put it in other tables?
0
by: UT-BadBoy | last post by:
Hi, I've been working with ASP.NET for about a year so I'm still considering myself to be somewhat of a novice in this field. I am receiving this particualr error when trying to hit a...
0
by: Narendra Gc | last post by:
Hi... I am looking after a lan . I am i am not able to access one particular system , by another one particular system. But from these computers i can access all other systems in my lan and...
4
by: ramdil | last post by:
Hi All I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns Now i have problem with the table,as my...
4
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but,...
4
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.