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. -
Option Compare Database
-
Option Explicit
-
Dim cnn As ADODB.Connection
-
Dim rst As New ADODB.Recordset
-
Public strSubject As String
-
Public strBody As String
-
-
Private Sub DupChk()
-
Dim btCount As Byte
-
Dim strSqlDupColl As String
-
Set cnn = CurrentProject.Connection
-
strSqlDupColl = "SELECT First(tblCollections.[CollectionID]) AS Coll, " & _
-
"First(tblCollections.[OfficeID]) AS Off, Count(tblCollections.[CollectionID]) AS DupsNum " & _
-
"FROM tblCollections " & _
-
"GROUP BY tblCollections.[CollectionID], tblCollections.[OfficeID] " & _
-
"HAVING (((Count(tblCollections.[CollectionID]))>1) AND ((Count(tblCollections.[OfficeID]))>1));"
-
rst.Open "strSqlDupColl", cnn, adOpenDynamic, adLockOptimistic
-
With rst
-
If rst.BOF And rst.EOF And btCount <> 1 Then
-
ImportUpd
-
btCount = 1
-
Else
-
strSubject = "Duplicate in tblCollections"
-
SendEmail
-
End If
9 2766 @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
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
@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: - rst.Open strSqlDupColl, cnn, adOpenDynamic, adLockOptimistic
@MikeTheBike
Sorry MikeTheBike, didn't realize that I was stepping on your toes.
@iheartvba
Can you Attach the Database, or a Subset of it?
@iheartvba
But did you get the same error message when there was no quotes?
@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
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.
@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
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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)
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |