Hi, All,
I created a small tool using VB6, in which I needed to insert some data
from Sybase database into an EXCEL file. I use an EXCEL template file with
only one row which will be recognized as each column name when connected
using ADO. It's OK to open the EXCEL file using ADO, and add new records to
it.
However, my problem is, each time when I connect the EXCEL file, I need
to delete existing records before adding new records, but I got error message
: run-time error '3219' - No operation is permitted in this environment. Why ?
I use VB ADODC control to do this, this is my code :
============================================
On Error GoTo ExcelConnectError
Dim strFileName As String
strFileName = "c:\Excel.xls"
adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFileName & ";" & _
"Extended Properties=""Excel
8.0;HDR=YES;"""
adodc1.RecordSource = "[" & "Sheet1$" & "]"
adodc1.Refresh
Dim nCount As Long
Dim nCnt As Long
nCount = adodc1.Recordset.RecordCount
If Not adodc1.Recordset.BOF Then
adodc1.Recordset.MoveFirst
End If
If nCount > 0 Then
adodc1.Recordset.MoveLast
For nCnt = 0 To (nCount - 1)
adodc1.Recordset.Delete
Next
adodc1.Recordset.Update
End If
ExcelConnectError:
strMsg = "File open error: " + strFileName
MsgBox strMsg, vbOKOnly, "ADO"
==========================================
Douglas J. Steele - 20 Jun 2007 22:32 GMT
It could be the same problem that prevents users of Access 2002 or newer to
update tables that are linked to Excel: Microsoft lost a lawsuit a couple of
years ago, and were forced to remove that capability.
You might have to resort to using Automation.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
> Hi, All,
>
[quoted text clipped - 50 lines]
>
> ==========================================
Kevin LZJ - 21 Jun 2007 03:45 GMT
Thanks, Doug !
I also got to know the fact that I coudn't delete records in EXECL using
ADO, however , you gave me more detailed information about it.
Kevin
> It could be the same problem that prevents users of Access 2002 or newer to
> update tables that are linked to Excel: Microsoft lost a lawsuit a couple of
> years ago, and were forced to remove that capability.
>
> You might have to resort to using Automation.
robert gabriel - 22 Jun 2007 17:03 GMT
So does your code work to update an excel file from access?