Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default MS Query "Connections"

You may add this to your macro to delete the names before/after your fetch.

For Each Name In Sheets("Data").Names
Name.Delete
Next Name
========
or use a refresh like this with variable interspersed.

With sheets("sheet1").QueryTables(1)
.Connection = _
"URL;http://www.speedtv.com/schedule/index.php?m=&do=&week=" & X &
"&ts=&wholeMonth=&subcat=&program=&usecal=yes&star tMonday=1"
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "1,""speedListing"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
=======
or

Sub GP()
With Sheets("sheet1").QueryTables(1)
.Connection = _
"URL;http://postcalc.usps.gov/MailServices.aspx?Country=Domestic&M="
& [mytype] & "&P=0&O=" & [myounces] & "&OZ=78734&DZ=78731"
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
--
Don Guillett
SalesAid Software

"Johnslg" wrote in message
...
I have a sheet that lets the user enter a chart of accounts in a column &
then a macro runs against each account (using QueryTable), hits an SQL
database, and returns data. My problem is that it adds a new connection
each
time the mcro runs. I just deleted about 400 connections.

Is there a way to reuse the same connection (it's all going against the
same
server/database) or is there a way to automatically delete connetions?

Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default MS Query "Connections"

Thanks. But I don't have names. I have a querytable connection inside a for
loop:

For Counter = 1 To 100 '....pick a number, I
could probably count the number of populated cells and get an exact #...

With Worksheets("Sheet1")
Result = ActiveCell.Offset(0, 1).Address 'Place return data
one cell to the right of current cell
End With
Worksheets("Sheet1").Range(Result).Clear 'Clear result cell
If MasterAccount = "" Then GoTo NEXTFOR 'Skip empty cells
If MasterAccount = "***" Then Exit For 'End of file token

With Range(Result).Cells 'Format return data
.NumberFormat = "$###,###,###.00"
.Font.Bold = True
.Font.Size = 10
.Font.Color = RGB(75, 0, 255)
.Font.TintAndShade = -0.5
End With

If InStr(MasterAccount, "~") = 0 Then 'check to see if two
account#'s concantenated
FirstAccountNumber = MasterAccount 'single account, set
account number parameter for query
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL
Server;SERVER=LLCSERVER2;UID=john.church;Trusted_C onnection=Yes;APP=2007
Microsoft Office system; " & _
"WSID=JC;DATABASE= & DataB & ",
Destination:=Range(Result), Sql:= _
"Select Sum(AMTRANDTL.AMTRDTranAmt) from AMTRANDTL "
& _
"left outer join GLACCTHDR on GLACCTHDR.GLACHNumber
= AMTRANDTL.GLACHNumber " & _
"left outer join AMTRANHDR on AMTRANHDR.AMTRHNumber
= AMTRANDTL.AMTRHNumber " & _
"where GLACHCode= '" & FirstAccountNumber & "' and
AMTRANHDR.AMTRHPeriod = '" & Period & "' Group By GLACCTHDR.GLACHCode")
.FieldNames = False
.RefreshStyle = xlOverwriteCells
.PreserveColumnInfo = True
.AdjustColumnWidth = False
.Refresh BackgroundQuery:=False
End With

"Don Guillett" wrote:

You may add this to your macro to delete the names before/after your fetch.

For Each Name In Sheets("Data").Names
Name.Delete
Next Name
========
or use a refresh like this with variable interspersed.

With sheets("sheet1").QueryTables(1)
.Connection = _
"URL;http://www.speedtv.com/schedule/index.php?m=&do=&week=" & X &
"&ts=&wholeMonth=&subcat=&program=&usecal=yes&star tMonday=1"
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "1,""speedListing"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
=======
or

Sub GP()
With Sheets("sheet1").QueryTables(1)
.Connection = _
"URL;http://postcalc.usps.gov/MailServices.aspx?Country=Domestic&M="
& [mytype] & "&P=0&O=" & [myounces] & "&OZ=78734&DZ=78731"
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
--
Don Guillett
SalesAid Software

"Johnslg" wrote in message
...
I have a sheet that lets the user enter a chart of accounts in a column &
then a macro runs against each account (using QueryTable), hits an SQL
database, and returns data. My problem is that it adds a new connection
each
time the mcro runs. I just deleted about 400 connections.

Is there a way to reuse the same connection (it's all going against the
same
server/database) or is there a way to automatically delete connetions?

Thanks.



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
Inhibit use of the function "Connections" on Excel 2007 Andrea Proietti Neri Setting up and Configuration of Excel 0 January 7th 10 06:28 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How to avoid "Data connections have been disabled" [email protected] Excel Discussion (Misc queries) 7 March 19th 08 01:14 PM
"Data Connections have been disabled" If no macros, Why? [email protected] Excel Discussion (Misc queries) 1 October 13th 07 01:26 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 06:45 PM.

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"