473,609 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA Distinct

1 New Member
Hello,

I'm a novice at VBA and hardly know the basics. However, i'm using Microsoft Access 2007 at the company i work at and i think i've finally come to the point where i can't avoid using SQL/VBA much longer.

I have duplicates in my database for 2 reasons:
-First of all the data that i am managing has duplicates, these tables aren't controlled by me though, i simply import and use them.
-I had to use a "create table" query in order for some of my work colleagues to manually fill in some fields newly created fields. Create table--> copy structure--add new fields with new data manually -->crush previous table to make new table with same data but with added fields manually.

This new table is then put in a query and that is where the main source of duplicates come from. Seeing as i've had to re-use tables from a previous query in this query because i have a few calculated fields that needed to be added and is impossible to be done prior to the creation of the new table. (hope i'm making sense). I guess this is my structure issue, but it is unavoidable unfortunately. Because i can't use my new calculated fields without the manual data.

So this means that i have a final query with more than 2000 duplicates instead of the previous 169 (impressive i know).

So the ideal situation would be to dispose of the duplicates in this final phase and i can't help but thinking that it would be so much easier if i knew SQL/VBA.

Does anyone have a simple easy to understand way of making my duplicates disappear or at least have unique data ?

Many thanks !
May 15 '15 #1
2 2435
Seth Schrock
2,965 Recognized Expert Specialist
The SELECT DISTINCT query will display only unique values, but it doesn't remove them from the table. In order to delete the duplicate records, I think the best way would be to create a ranking query (see Ranking Queries in MS Access) and delete records where the rank is greater than 1. You would obviously have to make the ranking query have the criteria to find duplicate records, thus including every field that would make it a duplicate record.
May 15 '15 #2
NeoPa
32,566 Recognized Expert Moderator MVP
In a situation such as this Guy, a properly organised structure progresses beyond a 'Nice to Have' and becomes 'Critical'.

Most of what you explain lacks the required level of detail for good advice. We can advise around bumps in the road, but are generally loathe to give advice that we understand will simply lead to your issues becoming bigger and more troublesome for you in the future.

Sure, you can get around individual instances of duplications, but without a thorough understanding of when duplicates appear and why that is a very risky approach. What it means in most cases (Again - too little information to be sure this pertains in yours.) is that the results become unreliable and, when treated as gospel as they often are, can be dangerously misleading.

My strong advice to you is to analyse why there are duplicates and put in place procedures to ensure they can no longer be created. Primary keys are useful in that context. Whether a randomly assigned one would help in your situation is hard to predict without an understanding of what that is.

The fact that you refer to them simply as duplicates, rather than duplicate XXXX type items, leads me to believe your appreciation of the situation and the related dangers is currently inadequate. Go and ensure you appreciate the whole system more clearly before trying to provide a computerised solution for the system. The latter approach will surely lead you to pain unless/until you retrace your steps back to the beginning and start again. You wouldn't be the first to take that route, but it's avoidable so don't be another even.

Whatever you choose I wish you good luck in your endeavours.
May 17 '15 #3

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

Similar topics

3
2164
by: ben | last post by:
This is a PHP / MySQL kind of question. I am making a script which simply pulls information from a database and displays it on screen. BUT there will be entries where fields could be the same, and I want to eliminate the duplicate entries when it displays it on screen. I would use, SELECT DISTINCT 'address1' FROM orders ....which does work, but only gives me one field. I also need to get a
5
11680
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the TransactionDate once as smalldatetime and once as varchar as I'm populating a drop-down with Text/Value pairs. So I can't just use 'SELECT DISTINCT TransactionDate FROM...' I'm grateful for any hints.
2
12539
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an "Column 'authors' in field list is ambiguous" error. Is there also a query to return only the count of distinct authors from the two tables? Thanks for any help.
18
3044
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are only returning one record. She states that with disctinct the query stops as soon as it finds a matching record. Both of us are relative novices in database theory (obviously). Can someone help settle this?
1
14477
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT aggregate function, but there is no reference, at least that I can find anywhere, of how to do this. I have multiple lines fields for which I would like to do a "count distinct", but for simplicity, I am showing an example of only one field. Here is...
3
5645
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada Inc
6
13552
by: Bob Stearns | last post by:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message: DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".  More exceptions ... DB2 SQL error:...
4
6140
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
2
5334
by: Techhead | last post by:
I need to run a SELECT DISTINCT query across multiple fields, but I need to add another field that is NON-DISTINCT to my record set. Here is my query: SELECT DISTINCT lastname, firstname, middleinitial, address1, address2, city, state, zip, age, gender FROM gpresults
10
6642
by: f houde | last post by:
Hi I have an access 2000 database and was asked to do some reporting with the data in it. There is one report I have to do would look like this : Select count(distinct Col1) as tot_col1, count(distinct Col2) as tot_col2, count(distinct Col3) as tot_col3, ... count(distinct Col15) as tot_col15,
0
8083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8224
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
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
7013
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...
0
5517
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
4091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2535
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
1
1676
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1393
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.