Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 03:21 PM
aml aml is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using FindNext

I am having a problem using the FindNext in Access VBA. I have two tables, table A and table B, where table A was created using a query to find duplicate records in Table B. I want to delete one of the duplicate records from Table A.

Here's my code:
Dim rsin As DAO.Recordset
Dim rsin2 As DAO.Recordset
Set rsin = db.OpenRecordset("ProToolDupes", dbOpenDynaset)
Set rsin2 = db.OpenRecordset("ProToolDataSorted", dbOpenDynaset)


rsin.MoveFirst
If rsin.Fields![Year] = "2006" Then
    rsin2.FindNext ("[project number] =" & rsin.Fields![project number])
     rsin2.Delete
End If

I am getting a 'data type mismatch' error.

If I set up the findnext statement as:

rsin2.findnext ("[project number]='01400113'")

it works perfectly (for that one record of course). What am I doing wrong with the statement syntax using a variable to set up the record key?

Any assistance will be greatly appreciated.

 
Old January 31st, 2007, 03:38 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Try this...

rsin2.FindNext ("[project number] ='" & rsin.Fields![project number]) & "'"

Mike

Mike
EchoVue.com
 
Old January 31st, 2007, 03:54 PM
aml aml is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are wonderful!!! Thanks so much!

 
Old February 1st, 2007, 02:08 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No Worries!! Welcome to the forum:)

Mike
EchoVue.com
 
Old February 1st, 2007, 09:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi, sorry I am late.

An easier way to do this whole process of removing duplicate records is to create a Make Table query on the dataset with the duplicates, and then select the query properties, and set the Unique Value property to Yes. Then run the query.

This removes the dupes and gives you a back up of the data at the same time.

Then either rename the dataset (table) with the dupes, and rename your new table to the old table name, or delete all the data in the old table and transfer in the new data (may have PK issues, but that is a different problem.)


HTH

mmcdonal









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.