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

I am trying to run a program that accesses one of our
database systems and creates a query table. I keep
getting the following error message "Run-Time Error 1004:
The operation cannot be done because the data is
refreshing in the background." If anyone has any
suggestions that would be great. My code is as follows:


Sub LFQuery()
' LFQuery Macro
' Macro recorded 6/21/2004 by Randy Kreider and Dale D.
Marques
' Declaring and Setting Variables
var1 = CStr(Worksheets("Customer").Range("F2").Value)
var2 = CStr(Worksheets("Customer").Range("F4").Value)
Worksheets("Customer").Unprotect
Range("A7:L18000").ClearContents
' Import Query Table
With ActiveSheet.QueryTables().Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for
Oracle};UID=;PWD=;SERVER=cdapd;", _
Destination:=Worksheets("Customer").Range("A7"))
.Sql = " SELECT CDM_LOCATIONS.OP_CENTER,
CDM_ESSR.METER_READ_DT, CDM_BILL_ACCOUNTS.BILL_ACCT_NUM,
CDM_BILL_ACCOUNTS.CUSTOMER_NAME,
CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION,
CDM_ESSR.REV_YR_MO, SUM(CDM_ESSR.KWH), SUM
(CDM_ESSR.MAXIMUM_DEMAND), SUM(CDM_ESSR.BILLED_DEMAND), SUM
(CDM_ESSR.COUNT_AS_BILL), SUM(CDM_ESSR.BILLING_DAYS)" & _
" FROM CDADM.CDM_LOCATIONS CDM_LOCATIONS,
CDADM.CDM_ESSR CDM_ESSR, CDADM.CDM_BILL_ACCOUNTS
CDM_BILL_ACCOUNTS, CDADM.CDM_SERVICE_SUPPLIERS
CDM_SERVICE_SUPPLIERS, CDADM.CDM_TARIFF_SCHEDULES
CDM_TARIFF_SCHEDULES " & _
" WHERE (CDM_LOCATIONS.LOCATION_GK_PK =
CDM_ESSR.LOCATION_FK) AND
(CDM_BILL_ACCOUNTS.BILL_ACCT_GK_PK =
CDM_ESSR.BILL_ACCT_FK ) AND (
CDM_TARIFF_SCHEDULES.TARIFF_SCHED_GK_PK =
CDM_ESSR.TARIFF_SCHED_FK) AND (CDM_ESSR.METER_READ_DT
BETWEEN TO_DATE('" & var1 & "','YYYYMMDD') AND TO_DATE('"
& var2 & "','YYYYMMDD')) AND
(CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION IN
(( 'LP6 ')) ) AND
(CDM_SERVICE_SUPPLIERS.SERVICE_SUPPLIER_GK_PK =
CDM_BILL_ACCOUNTS.SERVICE_SUPPLIER_FK)" & _
" GROUP BY CDM_LOCATIONS.OP_CENTER,
CDM_ESSR.METER_READ_DT, CDM_BILL_ACCOUNTS.BILL_ACCT_NUM,
CDM_BILL_ACCOUNTS.CUSTOMER_NAME,
CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION,
CDM_ESSR.REV_YR_MO"
' Query Table Formatting
.FieldNames = False
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = False
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery = False
.SavePassword = True
.SaveData = True
End With
Worksheets("Customer").Protect DrawingObjects = True,
contents = True, Scenarios = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Query Tables

Dale

On which line do you get the error? Do you get it every time you run it,
just the first time, or just any time after the first time?

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Dale Marques" wrote in message
...
I am trying to run a program that accesses one of our
database systems and creates a query table. I keep
getting the following error message "Run-Time Error 1004:
The operation cannot be done because the data is
refreshing in the background." If anyone has any
suggestions that would be great. My code is as follows:


Sub LFQuery()
' LFQuery Macro
' Macro recorded 6/21/2004 by Randy Kreider and Dale D.
Marques
' Declaring and Setting Variables
var1 = CStr(Worksheets("Customer").Range("F2").Value)
var2 = CStr(Worksheets("Customer").Range("F4").Value)
Worksheets("Customer").Unprotect
Range("A7:L18000").ClearContents
' Import Query Table
With ActiveSheet.QueryTables().Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for
Oracle};UID=;PWD=;SERVER=cdapd;", _
Destination:=Worksheets("Customer").Range("A7"))
.Sql = " SELECT CDM_LOCATIONS.OP_CENTER,
CDM_ESSR.METER_READ_DT, CDM_BILL_ACCOUNTS.BILL_ACCT_NUM,
CDM_BILL_ACCOUNTS.CUSTOMER_NAME,
CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION,
CDM_ESSR.REV_YR_MO, SUM(CDM_ESSR.KWH), SUM
(CDM_ESSR.MAXIMUM_DEMAND), SUM(CDM_ESSR.BILLED_DEMAND), SUM
(CDM_ESSR.COUNT_AS_BILL), SUM(CDM_ESSR.BILLING_DAYS)" & _
" FROM CDADM.CDM_LOCATIONS CDM_LOCATIONS,
CDADM.CDM_ESSR CDM_ESSR, CDADM.CDM_BILL_ACCOUNTS
CDM_BILL_ACCOUNTS, CDADM.CDM_SERVICE_SUPPLIERS
CDM_SERVICE_SUPPLIERS, CDADM.CDM_TARIFF_SCHEDULES
CDM_TARIFF_SCHEDULES " & _
" WHERE (CDM_LOCATIONS.LOCATION_GK_PK =
CDM_ESSR.LOCATION_FK) AND
(CDM_BILL_ACCOUNTS.BILL_ACCT_GK_PK =
CDM_ESSR.BILL_ACCT_FK ) AND (
CDM_TARIFF_SCHEDULES.TARIFF_SCHED_GK_PK =
CDM_ESSR.TARIFF_SCHED_FK) AND (CDM_ESSR.METER_READ_DT
BETWEEN TO_DATE('" & var1 & "','YYYYMMDD') AND TO_DATE('"
& var2 & "','YYYYMMDD')) AND
(CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION IN
(( 'LP6 ')) ) AND
(CDM_SERVICE_SUPPLIERS.SERVICE_SUPPLIER_GK_PK =
CDM_BILL_ACCOUNTS.SERVICE_SUPPLIER_FK)" & _
" GROUP BY CDM_LOCATIONS.OP_CENTER,
CDM_ESSR.METER_READ_DT, CDM_BILL_ACCOUNTS.BILL_ACCT_NUM,
CDM_BILL_ACCOUNTS.CUSTOMER_NAME,
CDM_TARIFF_SCHEDULES.TARIFF_RATE_DESIGNATION,
CDM_ESSR.REV_YR_MO"
' Query Table Formatting
.FieldNames = False
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = False
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery = False
.SavePassword = True
.SaveData = True
End With
Worksheets("Customer").Protect DrawingObjects = True,
contents = True, Scenarios = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Query Tables


The error comes in the line directly following :
.refresh backgroundquery = false, which is the
.savepassword =true, line.

I tried removing that line and when I did it did the same
error one the line following. So I removed that libe and
then it ran with errors but did not bring up any data. I
have run the query in Oracle Discoverer, so the query
works fine. I dont know if there is any problems with my
top connection statement or not. Also at some points I do
get an SQL error. But that is if I delete spaces out of
the sql lines.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Query Tables

the query itself has .Backgroundquery to true

in my experience
the refresh with bgqry argument false will NOT override it :(
(certainly when it hasn't executed before)

so what you do:
qt.backgroundquery = false
qt.refresh
ws.protect

the sheet is protected only when control is returned to the running
procedure e.g. ADO's STATE is DONE.

what would you expect to happen when the qt autorefreshes?
OR when you try to protect a sheet while ado's state is 'fetching'

conclusion:
the backgroundrefresh CANNOT en NEVER be true on protected sheets.
unless you fiddle with the settings till kingdom come...and you're sure
that the query under ALL circumstances:
will return the same number of fields and records.
will never OVERRIDE the cells, but UPDATE the cells.
preserveformatting is true
the table's cells are UNLOCKED
etc etc.

solution:
execute the queries on UNPROTECTED (but VERYHIDDEN?) sheets
get the data from there.



you'll need code needs to refresh
ws unprotect
qt.refresh
ws.protect



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Dale Marques" wrote:

.FieldNames = False
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = False
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery = False
.SavePassword = True
.SaveData = True
End With
Worksheets("Customer").Protect DrawingObjects = True,
contents = True, Scenarios = True
End Sub


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
MS Query - Joining two tables.... Marc T Excel Discussion (Misc queries) 1 September 10th 09 04:18 PM
Web query doesn't allow me to select tables cmarcus Excel Discussion (Misc queries) 0 August 12th 09 09:34 PM
MS Query No visible tables ChrisP Excel Discussion (Misc queries) 3 September 6th 05 08:51 PM
Web Query from multiple tables jjbf22 Excel Discussion (Misc queries) 0 July 29th 05 03:28 PM
Two Excel tables in MS Query Jamshed Excel Discussion (Misc queries) 0 June 24th 05 12:33 PM


All times are GMT +1. The time now is 08:03 PM.

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

About Us

"It's about Microsoft Excel"