Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro fails when not performing "step into"


Hello, I am rather new to excel, but was required to develope a script
for work. This script is designed to read data from a Citadel database
for Lookout (SCADA software), add the current runtime information to a
value stored in an MS SQL database, and insert it into the MS SQL
database. This needed to be done because the Citadel database drops the
data after 1 year, so equipment runtime can not be tracked.

I developed 3 scripts, 1 for reading the data from the MSSQL server
(like the last time script was run), next data is read from the Citadel
DB, and the last script is for writing the data back into MSSQL.

The 3 scripts do what they are supposed to when run seperatly by hand,
but we need to combine these into 1 script that will automatically run.
When I merged the scripts, they no longer worked. If I run the combined
macro with the "Step Into" line by line, it works.

Does excel not insert data acquired from a database until the macro is
done executing, which would explain why the next steps can not use the
data?

Here is the long, poorly written mess I call my script:

Sub Doall()

Dim lRealLastRow As Long
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, , xlByRows,
_
xlPrevious).Row

' --- Readcmms ---

For countnum = 1 To lRealLastRow
'countnum = "4"

With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=SQLOLEDB.1;Password=****;Persi st Security
Info=True;User ID=bob;Initial Catalog=entWORK;Data Source=SQLSERVER;Use
Pr" _
, _
"ocedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=PC2400-1003;Use Encryption for Data=False;Tag
with col" _
, "umn collation when possible=False"), Destination:=Range("D"
& countnum))
..CommandType = xlCmdSql
..CommandText = Array( _
"SELECT UDFChar5 FROM Asset WHERE ""AssetID"" = '" &
ActiveSheet.Range("A" & countnum) & "'; UPDATE ""dbo"".""Asset"" SET
""UDFChar5"" = '" & Now() & "'WHERE ""AssetID"" = '" &
ActiveSheet.Range("A" & countnum) & "'" _
)
..Name = "SQLSERVER entWORK_1"
..FieldNames = False
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..BackgroundQuery = False
..RefreshStyle = xlOverwriteCells
..SavePassword = True
..SaveData = True
..AdjustColumnWidth = True
..RefreshPeriod = 0
..PreserveColumnInfo = True
..SourceConnectionFile = _
"C:\Documents and Settings\bob\My Documents\My Data
Sources\SQLSERVER entWORK.odc"
..Refresh BackgroundQuery = False
' ActiveSheet.Range("C1") = Now()
End With

With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=SQLOLEDB.1;Password=****;Persi st Security
Info=True;User ID=bob;Initial Catalog=entWORK;Data Source=SQLSERVER;Use
Pr" _
, _
"ocedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=PC2400-1003;Use Encryption for Data=False;Tag
with col" _
, "umn collation when possible=False"), Destination:=Range("E"
& countnum))
..CommandType = xlCmdSql
..CommandText = Array( _
"SELECT Meter1Reading FROM Asset WHERE ""AssetID"" = '" &
ActiveSheet.Range("A" & countnum) & "';" _
)
..Name = "SQLSERVER entWORK_1"
..FieldNames = False
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..BackgroundQuery = False
..RefreshStyle = xlOverwriteCells
..SavePassword = True
..SaveData = True
..AdjustColumnWidth = True
..RefreshPeriod = 0
..PreserveColumnInfo = True
..SourceConnectionFile = _
"C:\Documents and Settings\bob\My Documents\My Data
Sources\SQLSERVER entWORK.odc"
..Refresh BackgroundQuery = False
ActiveSheet.Range("C" & countnum) = Now()
End With

Next countnum

* MORE CODE (~150 lines)... cut out to keep post short. The queries are
mostly the same, just different CommandText. If rest would help reply
so*

End Sub


--
shrek
------------------------------------------------------------------------
shrek's Profile: http://www.excelforum.com/member.php...o&userid=26047
View this thread: http://www.excelforum.com/showthread...hreadid=393932

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
Print just the list after performing a "find all" in Excel Office Minion Excel Worksheet Functions 0 December 11th 09 06:31 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
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
how to release anchored cell in EXCEL when hitting "esc" fails? L Excel Discussion (Misc queries) 1 April 15th 06 01:03 AM
"Multiple-step operation generated errors" Michael Daly Excel Programming 2 December 22nd 03 09:30 AM


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