LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default VBA excel - problem with having clause in sql with adodb.conne

Hi Kiran

ADO doesn't care what the SQL string is that you send through to the
database. It is just passing that to the back end and then returning the
results to you. So yes you can use a having statement in your query as long
as Oracle supports it. As Oracle supports standard SQL then you're OK on
that front.

I would guess that the error is telling you that no records are being
returned. This is probably down to one of two things:
1. Your query is valid and there are no duplicates in the table. , or
2. Your query is invalid and hence returning no records.

Are you sure there are duplicates in the database table? If there are dupes,
can you test your query string against the database in some other way?

I would suggest code something like the following (Note this is targetted at
the Northwind database in Access):

Sub test()

Const CONN As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb;Persist
Security Info=False"

Dim objRS As ADODB.Recordset
Dim objConn As ADODB.Connection

Dim strSQL As String
Dim lngRecordCount As Long

Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset

'open a connection explicitly
objConn.Open CONN

'build the SQL string
strSQL = "SELECT [Order Details].OrderID " & _
"FROM [Order Details] " & _
"GROUP BY [Order Details].OrderID " & _
"HAVING Count([Order Details].OrderID)1"

'open the recordset
objRS.Open strSQL, CONN, adOpenKeyset

'check for errors
If objConn.Errors.Count = 0 Then
'no errors

'check for returned records which have duplicate order ID's
lngRecordCount = objRS.RecordCount
If lngRecordCount 0 Then
MsgBox lngRecordCount & " duplicates found!"
Else
MsgBox "No duplicate records found!"
End If

Else
'SQL Errors returned, check the errors collection
'Note: Should loop through the errors collection to pickup all errors
MsgBox "There were errors." & vbLf & "Error 1: " &
objConn.Errors(0).Description
End If

End Sub

HTH

Barry


"ukp9999" wrote:


Barry,

i tried but getting the same error.
can we use have clause in adodb object?

thanks

Kiran


--
ukp9999
------------------------------------------------------------------------
ukp9999's Profile: http://www.excelforum.com/member.php...o&userid=28853
View this thread: http://www.excelforum.com/showthread...hreadid=486019


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB Connection Problem alpder Excel Programming 3 November 4th 05 09:28 PM
problem using isnull() to check a value in ADODB.Recordset tilmP Excel Programming 0 January 18th 05 07:42 AM
share adodb connection in excel Marek Excel Programming 3 September 7th 04 08:56 AM
ADODB Recordset problem Stefen Percoco Excel Programming 2 July 26th 04 06:31 PM
adodb.recordset with excel nate axtell Excel Programming 14 June 11th 04 01:32 PM


All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"