473,508 Members | 2,119 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 3084
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.Application
Set objExcel = New Excel.Application
Dim stDocName As String
Dim strSQL As String

DoCmd.SetWarnings False

Set DB = CurrentDb()

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

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

If Range("A1").Value <> "StrInward_No" _
Or Range("B1").Value <> "Inward_Date" _
Or Range("C1").Value <> "Hospital_Name" _
Or Range("D1").Value <> "Date_of_Admin" _
Or Range("E1").Value <> "Date_of_Discharge" _
Or Range("F1").Value <> "Claim_Amt" _
Or Range("G1").Value <> "Policy_No" _
Or Range("H1").Value <> "Policy_Name" _
Or Range("I1").Value <> "UHID_Fast_Track" _
Or Range("J1").Value <> "Name_of_Patient" _
Or Range("K1").Value <> "Claim_Rec_Date" _
Or Range("L1").Value <> "Claim_Type" _
Or Range("M1").Value <> "Claim_Status" _
Or Range("N1").Value <> "Claim_No" _
Or Range("O1").Value <> "Reason_Description" _
Or Range("P1").Value <> "Final_Query_Status" _
Or Range("Q1").Value <> "Actual_Query_Date" _
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.OpenRecordset("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("StrInward_No") = Range("A" & r).Value ' add values to each field in the record
.Fields("Inward_Date") = Range("B" & r).Value
.Fields("Hospital_Name") = Range("C" & r).Value
.Fields("Date_of_Admin") = Range("D" & r).Value
.Fields("Date_of_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_Fast_Track") = Range("I" & r).Value
.Fields("Name_of_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.Application.DisplayAlerts = False
ActiveWorkbook.Close


DoCmd.SetWarnings 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.12345 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
5814
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)...
9
5078
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...
0
1164
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...
4
2240
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 ?...
3
1559
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...
5
4614
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...
1
2225
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...
4
5947
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...
4
5421
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...
0
7225
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,...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
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...
0
5629
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,...
1
5053
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...
0
3195
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
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 ...

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.