473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Error Running Find Duplicates Query using ADO

171 100+
To put the below code simply, I have created a find duplicates query for a table using the Access query wizard. I have then tried to plug the Sql String (strSqlDupColl) copied from the Query Builder into VBA, using ADO I have tried to call the Query, but I get the following error : Invalid SQL statement expected; ‘DELETE’,’INSERT’,'UPDATE' or SELECT". I have no idea why this is occuring. Please help.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Dim cnn As ADODB.Connection
  4. Dim rst As New ADODB.Recordset
  5. Public strSubject As String
  6. Public strBody As String
  7.  
  8. Private Sub DupChk()
  9. Dim btCount As Byte
  10. Dim strSqlDupColl As String
  11. Set cnn = CurrentProject.Connection
  12. strSqlDupColl = "SELECT First(tblCollections.[CollectionID]) AS Coll, " & _
  13. "First(tblCollections.[OfficeID]) AS Off, Count(tblCollections.[CollectionID]) AS DupsNum " & _
  14. "FROM tblCollections " & _
  15. "GROUP BY tblCollections.[CollectionID], tblCollections.[OfficeID] " & _
  16. "HAVING (((Count(tblCollections.[CollectionID]))>1) AND ((Count(tblCollections.[OfficeID]))>1));"
  17. rst.Open "strSqlDupColl", cnn, adOpenDynamic, adLockOptimistic
  18.     With rst
  19.         If rst.BOF And rst.EOF And btCount <> 1 Then
  20.             ImportUpd
  21.                 btCount = 1
  22.         Else
  23.         strSubject = "Duplicate in tblCollections"
  24.          SendEmail
  25.         End If
Aug 18 '09 #1
9 2766
MikeTheBike
639 Expert 512MB
@iheartvba
Hi
Without looking too far into the code, I suggest first you remove the Quote marks round the query variable, ie. this

rst.Open "strSqlDupColl", cnn, adOpenDynamic, adLockOptimistic

should be this

rst.Open strSqlDupColl, cnn, adOpenDynamic, adLockOptimistic

??

MTB
Aug 18 '09 #2
iheartvba
171 100+
sorry about that mike, that was just me trying different things to get the code to work. Originally there were no quotes around strSqlDupColl and it was still not working.

Thanks
Aug 18 '09 #3
ADezii
8,834 Expert 8TB
@iheartvba
Before you attempt anything else, remove the Quotations from the strSqlDupColl String Variable, because ADO will interpret it as a Literal String, Replace Line #17 with:
Expand|Select|Wrap|Line Numbers
  1. rst.Open strSqlDupColl, cnn, adOpenDynamic, adLockOptimistic 
Aug 18 '09 #4
ADezii
8,834 Expert 8TB
@MikeTheBike
Sorry MikeTheBike, didn't realize that I was stepping on your toes.
Aug 18 '09 #5
ADezii
8,834 Expert 8TB
@iheartvba
Can you Attach the Database, or a Subset of it?
Aug 18 '09 #6
FishVal
2,653 Expert 2GB
@iheartvba
But did you get the same error message when there was no quotes?
Aug 18 '09 #7
MikeTheBike
639 Expert 512MB
@ADezii
Hi ADezil

There does not seem to be any damage, all toes seem to be functioning OK, but thanks for the concern!

Back on topic, iheartvba, an answer to FishVals question would be of some help.

MTB
Aug 19 '09 #8
iheartvba
171 100+
Ummm, it seems to be working now. I could very well have been putting quotes around the variables, sorry guys! Thanks for your help, it is greatly appreciated.
Aug 19 '09 #9
iheartvba
171 100+
@iheartvba
Actually I was right it still isn't working when I put a query made via the find duplicates query wizard via ADO, but I have just done my own find duplicates query, so It would be ok if someone wants to close this topic (sorry I don't know how to close the topic)

Thanks every1 for your help
Aug 21 '09 #10

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

Similar topics

11
by: David Berry | last post by:
Hi All. I have a SQL Statement on an ASP page that only returns 4 records. When I run it in SQL Server or Query Analyzer it runs in less than a second. When I run it from my ASP page I get: ...
0
by: Morten Gulbrandsen | last post by:
mysql> USE company; Database changed mysql> mysql> DROP TABLE IF EXISTS EMPLOYEE; -------------- DROP TABLE IF EXISTS EMPLOYEE -------------- Query OK, 0 rows affected (0.00 sec)
0
by: JC | last post by:
I am using Mysql version: 4.0.18-max-log and trying to populate a database from a text file using source option from inside the mysql environment. The population run OK but when creating the...
3
by: Tom Mitchell | last post by:
All: I'm stumped on a query. How do I find duplicates in a table where one of the duplicates has values is a certain field and the other doesn't. For example, I have the following table: ...
2
by: Phil | last post by:
Hi. I have a table containing primary address, secondary address, road,town, postcode, there are otherfields within the table requestid, round, day, etc. I want to find all instances of the...
2
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
6
by: boliches64 | last post by:
I am trying to delete duplicate records from a table. I have successfully created a query to find the duplicates. My problem is running the query in the following statement SQLDeleteDuplicates =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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,...

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.