Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default tuncating a table in sql from excel

I have the following code in an excel module. The line that has "Truncate
Table" in it is where it is failing. I am at a loss as to why and have not
been able to fix it.

Sub Worksheet_Change()
Dim conn As Object

Set conn = CreateObject("ADODB.Connection")

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and
Settings\jevans\Desktop\TestFolder\D_dd_ticker_lis t_fds.xls;" & _
"Extended Properties='Excel 8.0;HDR=Yes'"

conn.Execute "Truncate Table [ODBC;Driver={SQL
Server};Server=Mobile29;Database=StockQuote;].tbl_StockQuote;"

conn.Execute "Insert Into [ODBC;Driver={SQL Server}; " & _
"Server=Mobile29; " & _

"Database=StockQuote;].tbl_StockQuote(stq_StockQuoteSymbol,stq_StockQuot eAmount)" & _
"Select
stq_StockQuoteSymbol,stq_StockQuoteAmount From [Sheet1$];"

End Sub


If I take out the "conn.execute truncate table" line, the coding works fine.
But it keeps adding to the table when I need to remove what is in the table.
Truncate should work but it isn't.

If anyone reviewing this sees what is wrong, let me know, and thanks for
reviewing and commenting.

.... john


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default tuncating a table in sql from excel

Nevermind. I think I have found a solution.
.... John


"JohnE" wrote:

I have the following code in an excel module. The line that has "Truncate
Table" in it is where it is failing. I am at a loss as to why and have not
been able to fix it.

Sub Worksheet_Change()
Dim conn As Object

Set conn = CreateObject("ADODB.Connection")

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and
Settings\jevans\Desktop\TestFolder\D_dd_ticker_lis t_fds.xls;" & _
"Extended Properties='Excel 8.0;HDR=Yes'"

conn.Execute "Truncate Table [ODBC;Driver={SQL
Server};Server=Mobile29;Database=StockQuote;].tbl_StockQuote;"

conn.Execute "Insert Into [ODBC;Driver={SQL Server}; " & _
"Server=Mobile29; " & _

"Database=StockQuote;].tbl_StockQuote(stq_StockQuoteSymbol,stq_StockQuot eAmount)" & _
"Select
stq_StockQuoteSymbol,stq_StockQuoteAmount From [Sheet1$];"

End Sub


If I take out the "conn.execute truncate table" line, the coding works fine.
But it keeps adding to the table when I need to remove what is in the table.
Truncate should work but it isn't.

If anyone reviewing this sees what is wrong, let me know, and thanks for
reviewing and commenting.

... john


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
Export Excel tuncating leading zeros while export to excel from da RHBKV Setting up and Configuration of Excel 1 July 15th 09 01:48 PM
Excel 2007 Macro specific table to generic table? Sue Excel Discussion (Misc queries) 3 June 1st 08 06:12 PM
Excel Pivot Table Plugin? (crosstab to data table) HoMoon115 Excel Discussion (Misc queries) 0 February 22nd 06 08:20 PM
retain table formatting when writing excel table to a txt file deanop Excel Programming 8 September 3rd 05 05:38 AM
Tuncating Data Rows CDAK Excel Discussion (Misc queries) 0 June 16th 05 09:05 PM


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