473,796 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Duplicate values in Ms Excel while uploading to Ms Access

31 New Member
I am uploading MS Excel data to Ms access as detailed below.

Ms. Excel

A(Column) B(Column) C(Column)
------------------------------------------------------------------------------------
1 | Apple
2 | Mango
3 | Banana

Ms Access

Name_of_Fruits
-----------------------
Apple
Grapes

While uploading, I want a message box that Column A and Row 1 ('Apple') in Excel already Exist in Access Database.

Kindly help me with an Example code or Deatiled code for the same. Iam a beginer in Ms. Access.

Regards,
Ananth
Sep 17 '08 #1
5 3100
FishVal
2,653 Recognized Expert Specialist
Hello, Ananth.

How do you perform Excel to Access data import?

Regards,
Fish
Sep 17 '08 #2
Tempalli
31 New Member
Hello, Ananth.

How do you perform Excel to Access data import?

Regards,
Fish
I am using the below code to upload an excel file to Access. Kindly help me where should i define the code for Duplication.

Private Sub Bulk_Upload()

On Error GoTo Err_myError

Dim strmsg As String
Dim mypath As String
Dim rst As DAO.Recordset
Dim DB As Database
Dim r As Long
Dim wkbk As Workbook
Dim strDupName As String, strSaveName As String
Dim objRange1 As Range
Dim objRange2 As Range
Dim objExcel As Excel.Applicati on
Set objExcel = New Excel.Applicati on
Dim stDocName As String
Dim strSQL As String

DoCmd.SetWarnin gs False

Set DB = CurrentDb()

If Len(Nz(Me.Locat ion, "")) = 0 Then
Me.Status.Value = "Select the Excel file to upload......... ..!"
Me.Location.Set Focus
Exit Sub
End If

Set wkbk = Workbooks.Open( Me.Location, True)

If Range("A1").Val ue <> "StrInward_ No" _
Or Range("B1").Val ue <> "Inward_Dat e" _
Or Range("C1").Val ue <> "Hospital_N ame" _
Or Range("D1").Val ue <> "Date_of_Ad min" _
Or Range("E1").Val ue <> "Date_of_Discha rge" _
Or Range("F1").Val ue <> "Claim_Amt" _
Or Range("G1").Val ue <> "Policy_No" _
Or Range("H1").Val ue <> "Policy_Nam e" _
Or Range("I1").Val ue <> "UHID_Fast_Trac k" _
Or Range("J1").Val ue <> "Name_of_Patien t" _
Or Range("K1").Val ue <> "Claim_Rec_Date " _
Or Range("L1").Val ue <> "Claim_Type " _
Or Range("M1").Val ue <> "Claim_Stat us" _
Or Range("N1").Val ue <> "Claim_No" _
Or Range("O1").Val ue <> "Reason_Descrip tion" _
Or Range("P1").Val ue <> "Final_Query_St atus" _
Or Range("Q1").Val ue <> "Actual_Query_D ate" _
Then

ActiveWorkbook. Close
Me.Status.Value = "The process cannot access the file" & " " & Me.Location & " " & "...Column Numbers does not match the required definition"
Me.Location = ""

Exit Sub
End If

Set rst = DB.OpenRecordse t("Claim_Status ", dbOpenDynaset)

r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0 ' repeat until first empty cell in column A
'
With rst
.AddNew ' create a new record

.Fields("StrInw ard_No") = Range("A" & r).Value ' add values to each field in the record
.Fields("Inward _Date") = Range("B" & r).Value
.Fields("Hospit al_Name") = Range("C" & r).Value
.Fields("Date_o f_Admin") = Range("D" & r).Value
.Fields("Date_o f_Discharge") = Range("E" & r).Value
.Fields("Claim_ Amt") = Range("F" & r).Value
.Fields("Policy _No") = Range("G" & r).Value
.Fields("Policy _Name") = Range("H" & r).Value
.Fields("UHID_F ast_Track") = Range("I" & r).Value
.Fields("Name_o f_Patient") = Range("J" & r).Value
.Fields("Claim_ Rec_Date") = Range("K" & r).Value
.Fields("Claim_ Type") = Range("L" & r).Value
.Fields("Claim_ Status") = Range("M" & r).Value
.Fields("Claim_ No") = Range("N" & r).Value
.Fields("Reason _Description") = Range("O" & r).Value
.Fields("Final_ Query_Status") = Range("P" & r).Value
.Fields("Actual _Query_Date") = Range("Q" & r).Value
.Update ' stores the new record
End With

r = r + 1 ' next row
Loop

rst.Close

Set rst = Nothing
Set DB = Nothing

Excel.Applicati on.DisplayAlert s = False
ActiveWorkbook. Close


DoCmd.SetWarnin gs True


Exit_myError:
Exit Sub
Err_myError:

MsgBox Err.Description

Resume Exit_myError

End Sub
Sep 18 '08 #3
FishVal
2,653 Recognized Expert Specialist
Do you want to restrict duplicates absolutely or do you want to warn about duplicate value and allow/reject record according to user response?

Also post please what field(s) / combination(s) of fields is(are) expected to be unique.

Regards,
Fish
Sep 18 '08 #4
Tempalli
31 New Member
Do you want to restrict duplicates absolutely or do you want to warn about duplicate value and allow/reject record according to user response?

Also post please what field(s) / combination(s) of fields is(are) expected to be unique.

Regards,
Fish
Dear Fish,

I want to restrict duplicates while uploading the excel data and to inform the user that the perticular cell in excel contains duplicate value which is already exist in access and the user cannot upload the data to access with duplicate values. Kindly remove the duplicate fields and re-upload.

The unique no is StrInward_No where the duplicate has to be restricted.

The output of Duplicate field should be shown in Me.Status.Value = "StrInward_No.1 2345 in Excel Row A5 is already exist in Ms Access StrInward_No Field. Kindly remove the duplicate field and re-upload"

Regards,
Ananth
Sep 19 '08 #5
FishVal
2,653 Recognized Expert Specialist
Hello, Ananth.

Let me outline the whole situation as I see it.
  • With the code you already have you can:
    • Check whether a value going to be imported already exists in the table. DCount() or DLookUp() function will help you here. I guess it will reduce code performance significantly, but it is by its very nature not that fast - I suppose we are talking of dozens or hundreds (in a worst case) records to be imported.
    • You should make a unique index on [StrInward_No] field or declare it as PK, or maybe you've already done this. If so, then trying to add record with duplicate [StrInward_No] value will generate error which could be trapped by
      Expand|Select|Wrap|Line Numbers
      1. On Error Goto ...
      2.  
      statement. When trapped, user will be warned and the record will be cancelled.
      This is expected to perform faster than the previous one.
  • As I've already said the whole code is not a best performing one. It will be better to link Excel sheet dynamically as table and perform import with append query. As long as [StrInward_No] field is indexed as unique irrelevant records will be omitted automatically.

Regards,
Fish
Sep 19 '08 #6

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

Similar topics

3
5832
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros) documents successfully. Is there anything we have to take care of, while handling uploads of excel documents with macros? Thanks in advance,
9
5102
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test code below): (a)When adding BitArrays to the ArrayList and then looping through the ArrayList I seem to access only the latest added BitArray and I'm not exactly clear on best way to access each BItArray in the ArrayList (b)When I try to remove...
0
1178
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a problem in uploading Excel data to the Database. While uploading my code reads Excel Data using OleDbReader and store into a dataset by looping through the OleDbReader result set. The problem is, if I give the date as mm/dd/yyyy format it accepts, but when I give the date in dd/mm/yyyy format, upto 8 rows of data it is reporting the date as invalid. After 8th row even if the date is there (dd/mm/yyyy format), it is...
4
2252
by: viki1967 | last post by:
Hi everyone. With ASP I register in DB Access rows of one file excel; this procedure works but problem: Access record double rows of file excel. You can exclude from registration double rows ? I attach the file excel record to access. I register with this logic:
3
1573
by: Tempalli | last post by:
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 ------------------------------------ Set rst = DB.OpenRecordset("Claim_Status", dbOpenDynaset)
5
4621
by: priyammaheshwari | last post by:
Hi all, I have a MS Access database in which requests made by people is stored,but a coulmn for cost is left empty which is suppose to be populated by the administrator.Now the administrator wants that there should be some functionality by which he would just have to upload an excel file containing the name and cost per person and the cost should be populated in access database against the respective name of people. I am not able to figure...
1
2243
by: codexxx | last post by:
Hi All, We have setup an Amazon webstore and we anticipate uploading 10,000+ products, and therefore to avoid unnecessary manual labor we wish to automate as much of the process of adding and managing products as possible. The automation process that we have in mind will require some manner of cross scripting. We currently have a database of our products and we are able to upload products to Amazon with no problems. Our database of...
4
5964
by: shodan | last post by:
Hi board, I'm using excel vba to drive my access database. Now I encountered the following problem: I have an update qry to update a table which has an index field. Because of this, I always get the error message that it won't let me update the table. I'm aware of the duplicates, but if I run the update query manually, I can ignore the error and it will only update my table with the first row and just drops the duplciates. This is exactly...
4
5467
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 the number of duplicate rows based on a particular cell value of each these duplicate rows. I mean all the cell values of a row will not be duplicated but a individual columns cell value will be duplicated and I need to create a separate excel with...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.