PC Review


Reply
Thread Tools Rate Thread

Check table for like values

 
 
hollyylloh
Guest
Posts: n/a
 
      13th Jun 2009
I am trying to do roughly as stated in this code sample. I am looking for
some advice on how to go about this the most efficiently as this will be run
over several thousand records at a time.

Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblImported")
Do While Not rs.EOF
rs.Edit

'Here I want to compare each value in the imported table against an existing
table to find possible duplicate values. Something like this:?

SELECT tblImported.Company FROM tblImported
WHERE (((tblImported.Company) Like '*' & [tblContacts]![Company]& '*'));

'Then on each record I want to separate out any entries that might have
similar values. These will be copied to a table for further processing.
Values without similar entries will be copied to a different table. So
something like this:?
'Count results
'If Count is > 1 then
'Copy record to table tblInProcess
'else
'copy record to table tblToExport
Loop
rs.Close

I would like to plan ahead and start with the best plan of action and then
work out the details of the code from there. Your advice would be
appreciated.

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      13th Jun 2009
Create a query that joins tblImported.Company to tblContacts.Company. Any
matches you get are duplicates.

Your example used the Like operator with wildcards. If you really need to do
that, you can switch the new query to SQL View, and edit the SQL statement
from:
FROM tblImported INNER JOIN tblContacts
ON tblImported.Company = tblContacts.Comany
to:
FROM tblImported INNER JOIN tblContacts
ON tblImported.Company Like "*" & tblContacts.Comany & "*"

If you are trying to do this programmatically, copy the SQL statement above
into your code, i.e.:
Dim strSql As String
strSql = "SELECT ...
Set rs = db.OpenRecordset(strSql)
If rs.RecordCount > 0 Then
MsgBox "Duplicates found"
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hollyylloh" <(E-Mail Removed)> wrote in message
news:853F0BCF-ACED-4EEA-82F0-(E-Mail Removed)...
>I am trying to do roughly as stated in this code sample. I am looking for
> some advice on how to go about this the most efficiently as this will be
> run over several thousand records at a time.
>
> Dim db As Database
> Dim rs As DAO.Recordset
> Set db = CurrentDb
> Set rs = db.OpenRecordset("tblImported")
> Do While Not rs.EOF
> rs.Edit
>
> 'Here I want to compare each value in the imported table against an
> existing table to find possible duplicate values. Something like this:?
>
> SELECT tblImported.Company FROM tblImported
> WHERE (((tblImported.Company) Like '*' & [tblContacts]![Company]& '*'));
>
> 'Then on each record I want to separate out any entries that might have
> similar values. These will be copied to a table for further processing.
> Values without similar entries will be copied to a different table. So
> something like this:?
> 'Count results
> 'If Count is > 1 then
> 'Copy record to table tblInProcess
> 'else
> 'copy record to table tblToExport
> Loop
> rs.Close
>
> I would like to plan ahead and start with the best plan of action and
> then work out the details of the code from there. Your advice would
> be appreciated.


 
Reply With Quote
 
hollyylloh
Guest
Posts: n/a
 
      16th Jun 2009
Thank you Allen that takes care of that question, thank you. I do have an
additional question that I will post here in case you may be able to help. I
am looking for a way to find more than just duplicates. I am looking for a
way to find near duplicates as well. So for example if I search for "Valley
Swim Park Association" I want an existing value of "Valley Swim Park
Facility" to be returned as a posible duplicate. Any Ideas?

"Allen Browne" wrote:

> Create a query that joins tblImported.Company to tblContacts.Company. Any
> matches you get are duplicates.
>
> Your example used the Like operator with wildcards. If you really need to do
> that, you can switch the new query to SQL View, and edit the SQL statement
> from:
> FROM tblImported INNER JOIN tblContacts
> ON tblImported.Company = tblContacts.Comany
> to:
> FROM tblImported INNER JOIN tblContacts
> ON tblImported.Company Like "*" & tblContacts.Comany & "*"
>
> If you are trying to do this programmatically, copy the SQL statement above
> into your code, i.e.:
> Dim strSql As String
> strSql = "SELECT ...
> Set rs = db.OpenRecordset(strSql)
> If rs.RecordCount > 0 Then
> MsgBox "Duplicates found"
> End If
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "hollyylloh" <(E-Mail Removed)> wrote in message
> news:853F0BCF-ACED-4EEA-82F0-(E-Mail Removed)...
> >I am trying to do roughly as stated in this code sample. I am looking for
> > some advice on how to go about this the most efficiently as this will be
> > run over several thousand records at a time.
> >
> > Dim db As Database
> > Dim rs As DAO.Recordset
> > Set db = CurrentDb
> > Set rs = db.OpenRecordset("tblImported")
> > Do While Not rs.EOF
> > rs.Edit
> >
> > 'Here I want to compare each value in the imported table against an
> > existing table to find possible duplicate values. Something like this:?
> >
> > SELECT tblImported.Company FROM tblImported
> > WHERE (((tblImported.Company) Like '*' & [tblContacts]![Company]& '*'));
> >
> > 'Then on each record I want to separate out any entries that might have
> > similar values. These will be copied to a table for further processing.
> > Values without similar entries will be copied to a different table. So
> > something like this:?
> > 'Count results
> > 'If Count is > 1 then
> > 'Copy record to table tblInProcess
> > 'else
> > 'copy record to table tblToExport
> > Loop
> > rs.Close
> >
> > I would like to plan ahead and start with the best plan of action and
> > then work out the details of the code from there. Your advice would
> > be appreciated.

>
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      16th Jun 2009
This is always thorny, and will require some human scanning, but there are
ways you can connect, e.g by joining:
ON Left(tblImported.Company, 10) LIKE "*" & Left(tblContacts.Comany, 10)
& "*"

For surnames, something like Soundex() may help:
http://allenbrowne.com/vba-Soundex.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hollyylloh" <(E-Mail Removed)> wrote in message
news:26386CEC-5C9F-4E40-B5AA-(E-Mail Removed)...
> Thank you Allen that takes care of that question, thank you. I do have an
> additional question that I will post here in case you may be able to help.
> I
> am looking for a way to find more than just duplicates. I am looking for a
> way to find near duplicates as well. So for example if I search for
> "Valley
> Swim Park Association" I want an existing value of "Valley Swim Park
> Facility" to be returned as a posible duplicate. Any Ideas?
>
> "Allen Browne" wrote:
>
>> Create a query that joins tblImported.Company to tblContacts.Company. Any
>> matches you get are duplicates.
>>
>> Your example used the Like operator with wildcards. If you really need to
>> do
>> that, you can switch the new query to SQL View, and edit the SQL
>> statement
>> from:
>> FROM tblImported INNER JOIN tblContacts
>> ON tblImported.Company = tblContacts.Comany
>> to:
>> FROM tblImported INNER JOIN tblContacts
>> ON tblImported.Company Like "*" & tblContacts.Comany & "*"
>>
>> If you are trying to do this programmatically, copy the SQL statement
>> above
>> into your code, i.e.:
>> Dim strSql As String
>> strSql = "SELECT ...
>> Set rs = db.OpenRecordset(strSql)
>> If rs.RecordCount > 0 Then
>> MsgBox "Duplicates found"
>> End If
>>
>> --
>> Allen Browne - Microsoft MVP. Perth, Western Australia
>> Tips for Access users - http://allenbrowne.com/tips.html
>> Reply to group, rather than allenbrowne at mvps dot org.
>>
>> "hollyylloh" <(E-Mail Removed)> wrote in message
>> news:853F0BCF-ACED-4EEA-82F0-(E-Mail Removed)...
>> >I am trying to do roughly as stated in this code sample. I am looking
>> >for
>> > some advice on how to go about this the most efficiently as this will
>> > be
>> > run over several thousand records at a time.
>> >
>> > Dim db As Database
>> > Dim rs As DAO.Recordset
>> > Set db = CurrentDb
>> > Set rs = db.OpenRecordset("tblImported")
>> > Do While Not rs.EOF
>> > rs.Edit
>> >
>> > 'Here I want to compare each value in the imported table against an
>> > existing table to find possible duplicate values. Something like this:?
>> >
>> > SELECT tblImported.Company FROM tblImported
>> > WHERE (((tblImported.Company) Like '*' & [tblContacts]![Company]&
>> > '*'));
>> >
>> > 'Then on each record I want to separate out any entries that might have
>> > similar values. These will be copied to a table for further processing.
>> > Values without similar entries will be copied to a different table. So
>> > something like this:?
>> > 'Count results
>> > 'If Count is > 1 then
>> > 'Copy record to table tblInProcess
>> > 'else
>> > 'copy record to table tblToExport
>> > Loop
>> > rs.Close
>> >
>> > I would like to plan ahead and start with the best plan of action and
>> > then work out the details of the code from there. Your advice would
>> > be appreciated.

>>
>>


 
Reply With Quote
 
hollyylloh
Guest
Posts: n/a
 
      20th Jun 2009
I can work with that, thank you!

"Allen Browne" wrote:

> This is always thorny, and will require some human scanning, but there are
> ways you can connect, e.g by joining:
> ON Left(tblImported.Company, 10) LIKE "*" & Left(tblContacts.Comany, 10)
> & "*"
>
> For surnames, something like Soundex() may help:
> http://allenbrowne.com/vba-Soundex.html
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "hollyylloh" <(E-Mail Removed)> wrote in message
> news:26386CEC-5C9F-4E40-B5AA-(E-Mail Removed)...
> > Thank you Allen that takes care of that question, thank you. I do have an
> > additional question that I will post here in case you may be able to help.
> > I
> > am looking for a way to find more than just duplicates. I am looking for a
> > way to find near duplicates as well. So for example if I search for
> > "Valley
> > Swim Park Association" I want an existing value of "Valley Swim Park
> > Facility" to be returned as a posible duplicate. Any Ideas?
> >
> > "Allen Browne" wrote:
> >
> >> Create a query that joins tblImported.Company to tblContacts.Company. Any
> >> matches you get are duplicates.
> >>
> >> Your example used the Like operator with wildcards. If you really need to
> >> do
> >> that, you can switch the new query to SQL View, and edit the SQL
> >> statement
> >> from:
> >> FROM tblImported INNER JOIN tblContacts
> >> ON tblImported.Company = tblContacts.Comany
> >> to:
> >> FROM tblImported INNER JOIN tblContacts
> >> ON tblImported.Company Like "*" & tblContacts.Comany & "*"
> >>
> >> If you are trying to do this programmatically, copy the SQL statement
> >> above
> >> into your code, i.e.:
> >> Dim strSql As String
> >> strSql = "SELECT ...
> >> Set rs = db.OpenRecordset(strSql)
> >> If rs.RecordCount > 0 Then
> >> MsgBox "Duplicates found"
> >> End If
> >>
> >> --
> >> Allen Browne - Microsoft MVP. Perth, Western Australia
> >> Tips for Access users - http://allenbrowne.com/tips.html
> >> Reply to group, rather than allenbrowne at mvps dot org.
> >>
> >> "hollyylloh" <(E-Mail Removed)> wrote in message
> >> news:853F0BCF-ACED-4EEA-82F0-(E-Mail Removed)...
> >> >I am trying to do roughly as stated in this code sample. I am looking
> >> >for
> >> > some advice on how to go about this the most efficiently as this will
> >> > be
> >> > run over several thousand records at a time.
> >> >
> >> > Dim db As Database
> >> > Dim rs As DAO.Recordset
> >> > Set db = CurrentDb
> >> > Set rs = db.OpenRecordset("tblImported")
> >> > Do While Not rs.EOF
> >> > rs.Edit
> >> >
> >> > 'Here I want to compare each value in the imported table against an
> >> > existing table to find possible duplicate values. Something like this:?
> >> >
> >> > SELECT tblImported.Company FROM tblImported
> >> > WHERE (((tblImported.Company) Like '*' & [tblContacts]![Company]&
> >> > '*'));
> >> >
> >> > 'Then on each record I want to separate out any entries that might have
> >> > similar values. These will be copied to a table for further processing.
> >> > Values without similar entries will be copied to a different table. So
> >> > something like this:?
> >> > 'Count results
> >> > 'If Count is > 1 then
> >> > 'Copy record to table tblInProcess
> >> > 'else
> >> > 'copy record to table tblToExport
> >> > Loop
> >> > rs.Close
> >> >
> >> > I would like to plan ahead and start with the best plan of action and
> >> > then work out the details of the code from there. Your advice would
> >> > be appreciated.
> >>
> >>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check TEXT BOX entry agains table info or EXCEPTION values kealaz Microsoft Access Database Table Design 5 22nd Jun 2009 06:03 PM
IIF to check values in more than one table =?Utf-8?B?S2FyZW5G?= Microsoft Access Database Table Design 1 19th Jul 2007 02:24 PM
Check textbox value against a table of stored values Carlos Microsoft Access Form Coding 1 6th Dec 2005 12:14 PM
Insert values into a table based on check box being on or off. =?Utf-8?B?Q0xVNzM=?= Microsoft Access 3 27th Jan 2005 10:56 PM
comparing check box values to a table Markathepub Microsoft Excel Misc 1 13th Feb 2004 05:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:44 AM.