Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default AODB Recordset

Hi, Please help...

This is my query below trying to extract data from Access into Excel. I am
having trouble withthe second part of the query. It works fine to bring in
the first SQL but then fails on the second and gives me this error message
"Operation is not allowed when the object is open"
I dont understand why its going wrong when I havent closed the connection
between the database but only closed when created the recordset.. How can I
fix this problem, as I may want to add another SQL to it?

Option Explicit

Dim cnnDW As ADODB.Connection
Dim rsDW As ADODB.Recordset
Dim sQRY As String
Dim strDWFilePath, strCSVFilePath, strDestFilePath, strDestFileName As String

Sub GetData()

On Error GoTo Err:
strDWFilePath = "H:\NCHO\Housing Services\Data Warehouse\HSG Data
Warehouse.mdb"

Set cnnDW = New ADODB.Connection

Set rsDW = New ADODB.Recordset
'ASV N Week by Contract
Sheet4.Range("B5:BB23").ClearContents
cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDWFilePath & ";"
sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
CountOfWRNumber " & _
"SELECT [qryNoAccess(byAppt)].CouncilName " & _
"FROM [qryNoAccess(byAppt)] " & _
"WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
(([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
(([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
"GROUP BY [qryNoAccess(byAppt)].CouncilName " & _
"PIVOT [qryNoAccess(byAppt)].Week"
rsDW.CursorLocation = adUseClient
rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet4.Range("B5").CopyFromRecordset rsDW
rsDW.Close
Set rsDW = Nothing

Set rsDW = New ADODB.Recordset
'ASV N Week by Neigbourhood
Sheet4.Range("B25:BB79").ClearContents
cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDWFilePath & ";"
sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
CountOfWRNumber " & _
"SELECT [qryNoAccess(byAppt)].CouncilDistrict " & _
"FROM [qryNoAccess(byAppt)] " & _
"WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
(([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
(([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
"GROUP BY [qryNoAccess(byAppt)].CouncilDistrict " & _
"PIVOT [qryNoAccess(byAppt)].Week"
rsDW.CursorLocation = adUseClient
rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet4.Range("B25").CopyFromRecordset rsDW
rsDW.Close
Set rsDW = Nothing

cnnDW.Close
Set cnnDW = Nothing
frmData.Hide

Exit Sub

Err:
MsgBox "The following error has occured-" & vbCrLf & vbCrLf & VBA.Error,
vbCritical, "HSG NA Trending"
MsgBox VBA.Err

End Sub


Thanks,
Jez


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default AODB Recordset

REM this line

On Error GoTo Err:

then tell us the line that the code errors on.



--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Jez" wrote:
| Hi, Please help...
|
| This is my query below trying to extract data from Access into Excel. I am
| having trouble withthe second part of the query. It works fine to bring in
| the first SQL but then fails on the second and gives me this error message
| "Operation is not allowed when the object is open"
| I dont understand why its going wrong when I havent closed the connection
| between the database but only closed when created the recordset.. How can
I
| fix this problem, as I may want to add another SQL to it?
|
| Option Explicit
|
| Dim cnnDW As ADODB.Connection
| Dim rsDW As ADODB.Recordset
| Dim sQRY As String
| Dim strDWFilePath, strCSVFilePath, strDestFilePath, strDestFileName As
String
|
| Sub GetData()
|
| On Error GoTo Err:
| strDWFilePath = "H:\NCHO\Housing Services\Data Warehouse\HSG Data
| Warehouse.mdb"
|
| Set cnnDW = New ADODB.Connection
|
| Set rsDW = New ADODB.Recordset
| 'ASV N Week by Contract
| Sheet4.Range("B5:BB23").ClearContents
| cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
| "Data Source=" & strDWFilePath & ";"
| sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
| CountOfWRNumber " & _
| "SELECT [qryNoAccess(byAppt)].CouncilName " & _
| "FROM [qryNoAccess(byAppt)] " & _
| "WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
| (([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
| (([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
| "GROUP BY [qryNoAccess(byAppt)].CouncilName " & _
| "PIVOT [qryNoAccess(byAppt)].Week"
| rsDW.CursorLocation = adUseClient
| rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
| Application.ScreenUpdating = False
| Sheet4.Range("B5").CopyFromRecordset rsDW
| rsDW.Close
| Set rsDW = Nothing
|
| Set rsDW = New ADODB.Recordset
| 'ASV N Week by Neigbourhood
| Sheet4.Range("B25:BB79").ClearContents
| cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
| "Data Source=" & strDWFilePath & ";"
| sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
| CountOfWRNumber " & _
| "SELECT [qryNoAccess(byAppt)].CouncilDistrict " & _
| "FROM [qryNoAccess(byAppt)] " & _
| "WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
| (([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
| (([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
| "GROUP BY [qryNoAccess(byAppt)].CouncilDistrict " & _
| "PIVOT [qryNoAccess(byAppt)].Week"
| rsDW.CursorLocation = adUseClient
| rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
| Application.ScreenUpdating = False
| Sheet4.Range("B25").CopyFromRecordset rsDW
| rsDW.Close
| Set rsDW = Nothing
|
| cnnDW.Close
| Set cnnDW = Nothing
| frmData.Hide
|
| Exit Sub
|
| Err:
| MsgBox "The following error has occured-" & vbCrLf & vbCrLf &
VBA.Error,
| vbCritical, "HSG NA Trending"
| MsgBox VBA.Err
|
| End Sub
|
|
| Thanks,
| Jez
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default AODB Recordset

Dave,

I dont really understand what you mean, but when the error box appears
saying Operation is not allowed when the object is open another box pops up
saying 3705

How can I fix this?

"Dave Patrick" wrote:

REM this line

On Error GoTo Err:

then tell us the line that the code errors on.



--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Jez" wrote:
| Hi, Please help...
|
| This is my query below trying to extract data from Access into Excel. I am
| having trouble withthe second part of the query. It works fine to bring in
| the first SQL but then fails on the second and gives me this error message
| "Operation is not allowed when the object is open"
| I dont understand why its going wrong when I havent closed the connection
| between the database but only closed when created the recordset.. How can
I
| fix this problem, as I may want to add another SQL to it?
|
| Option Explicit
|
| Dim cnnDW As ADODB.Connection
| Dim rsDW As ADODB.Recordset
| Dim sQRY As String
| Dim strDWFilePath, strCSVFilePath, strDestFilePath, strDestFileName As
String
|
| Sub GetData()
|
| On Error GoTo Err:
| strDWFilePath = "H:\NCHO\Housing Services\Data Warehouse\HSG Data
| Warehouse.mdb"
|
| Set cnnDW = New ADODB.Connection
|
| Set rsDW = New ADODB.Recordset
| 'ASV N Week by Contract
| Sheet4.Range("B5:BB23").ClearContents
| cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
| "Data Source=" & strDWFilePath & ";"
| sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
| CountOfWRNumber " & _
| "SELECT [qryNoAccess(byAppt)].CouncilName " & _
| "FROM [qryNoAccess(byAppt)] " & _
| "WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
| (([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
| (([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
| "GROUP BY [qryNoAccess(byAppt)].CouncilName " & _
| "PIVOT [qryNoAccess(byAppt)].Week"
| rsDW.CursorLocation = adUseClient
| rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
| Application.ScreenUpdating = False
| Sheet4.Range("B5").CopyFromRecordset rsDW
| rsDW.Close
| Set rsDW = Nothing
|
| Set rsDW = New ADODB.Recordset
| 'ASV N Week by Neigbourhood
| Sheet4.Range("B25:BB79").ClearContents
| cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
| "Data Source=" & strDWFilePath & ";"
| sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
| CountOfWRNumber " & _
| "SELECT [qryNoAccess(byAppt)].CouncilDistrict " & _
| "FROM [qryNoAccess(byAppt)] " & _
| "WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
| (([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
| (([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
| "GROUP BY [qryNoAccess(byAppt)].CouncilDistrict " & _
| "PIVOT [qryNoAccess(byAppt)].Week"
| rsDW.CursorLocation = adUseClient
| rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
| Application.ScreenUpdating = False
| Sheet4.Range("B25").CopyFromRecordset rsDW
| rsDW.Close
| Set rsDW = Nothing
|
| cnnDW.Close
| Set cnnDW = Nothing
| frmData.Hide
|
| Exit Sub
|
| Err:
| MsgBox "The following error has occured-" & vbCrLf & vbCrLf &
VBA.Error,
| vbCritical, "HSG NA Trending"
| MsgBox VBA.Err
|
| End Sub
|
|
| Thanks,
| Jez
|
|



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default AODB Recordset

Remove this line;

On Error GoTo Err:

Then tell us the line the code stops on.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Jez" wrote:
| Dave,
|
| I dont really understand what you mean, but when the error box appears
| saying Operation is not allowed when the object is open another box pops
up
| saying 3705
|
| How can I fix this?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default AODB Recordset

You're attempting to open the connection twice.

cnnDW.Open

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect




Reply
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
AODB Recordset Jez[_7_] Excel Programming 0 November 12th 06 02:00 PM
Need ADO Recordset Help Mr B[_2_] Excel Programming 9 April 21st 06 04:51 PM
Several sql queries with the same recordset fbonnard Excel Programming 2 November 2nd 04 05:50 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM


All times are GMT +1. The time now is 02:17 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"