LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
LD LD is offline
external usenet poster
 
Posts: 10
Default Truncate, Insert, or Update SQL command in EXCEL Macro

I want to do other types of SQL commands in an EXCEL macro besides standard
"select" queries. In particular, I'd like to do a "truncate table" , and also
an "Insert" and an "Update". I recorded a macro to do a "select", thinking I
would then just edit the "select" statement to do what I want, but it does
not appear to do anything when I execute it. Here's a sample of the code that
was recorded. The query is passed to an ORACLE database through an ODBC
connection.

Step 2 will be to pass some parameters (data) to SQL in the insert and
update commands. Any suggestions and examples would be most sincerely
appreciated. Thanks!

Sub Exec_Query()
'
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=lss;UID=userid;PWD=password;DBQ=LSS; DBA=
W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=
T;BTD=F;BAM=IfAllSuccessful;NUM=N" _
), Array("LS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000; TLO=O;")),
Destination:= _
Range("A1"))
..CommandText = Array( _
"SELECT var1, var2" & Chr(13) & "" & Chr(10) & "FROM master_tbl" & Chr(13) &
"" & Chr(10) & "WHERE (var1 = var2)")
..Name = "Query"
..FieldNames = True
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..BackgroundQuery = True
..RefreshStyle = xlInsertDeleteCells
..SavePassword = True
..SaveData = True
..AdjustColumnWidth = True
..RefreshPeriod = 0
..PreserveColumnInfo = True
..Refresh BackgroundQuery:=False
End With
End Sub

 
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
can i write a macro to truncate alpha-numeric data? T-Dot Excel Discussion (Misc queries) 2 August 12th 06 08:15 AM
How do I set up macro to truncate column/field? Macro to truncate column Excel Programming 4 June 29th 06 06:09 PM
How can I insert a run macro command in the IF function? emil Excel Programming 4 April 15th 06 02:57 PM
Can I insert roundup command into different formulas in excel? Margaret Excel Worksheet Functions 4 August 5th 05 12:22 PM
How to execute an SQL insert/update from Excel for Mac Laphan[_2_] Excel Programming 1 June 22nd 04 09:01 PM


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