Re: INSERT INTO Excel file, from an Access source

From: Programmer Dude (Chris_at_Sonnack.com)
Date: 01/15/04


Date: Thu, 15 Jan 2004 15:38:19 -0600

Patrick Lioi wrote:

> An existing application, which works, and was written by someone
> else, executes this bit of SQL:
>
> strSQL = "INSERT INTO [Shee1$] IN '' [Excel 8.0;Database=" & XLS_PATH
> & "] SELECT a, b, c FROM tablename"

Don't know if this is relevant, but I tried this (in Access), and
it didn't work at all. I changed it to this, and it worked fine:

INSERT INTO [Excel 8.0;Database=C:\path\Test.xls].[Sheet1$]
(a, b, c)
SELECT a, b, c FROM tablename ORDER BY a;

SQL syntax does vary among products, so this may not apply.

> This WORKS on the production computer, but fails *quietly* on my
> development computer. The only source code change is the value of
> XLS_PATH, which now points to a file on my development computer.
>
> Rarely, the excel file actually will be updated. Most of the time,
> it avoids updating without any error messages.
>
> Any idea what could be different between the production and dev
> environments to cause this behavior?

Same versions of Excel? Same versions of the underlying DB and
OLE drivers?

I found that--in my test--"Sheet1" had to exist, and it had to
have the field names in the first row. There's probably a way
around that last, but I don't have the time to pursue it.

ONE SUGGESTION: it may be (much) easier to create a query IN
Excel that pulls the data from the database rather than trying
to extract it and stuff it into Excel from the outside.

-- 
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL  |
|_____________________________________________|_______________________|


Relevant Pages

  • Re: How to add upload excel file and insert into SQL Compact Editi
    ... collects data that we eventually export to Excel, CSV, Sql ... do you ever import data from Excel file into SQL 2005 ... different kinds of text file formats. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Cant get SQL INSERT code to work
    ... I'm not sure you can use SQL to add data to an Excel file from another ... From Access Help file (covers JET SQL): ... ' Create the connection string. ... > 'Excel file and modify the SQL statement to fit your data. ...
    (microsoft.public.access.queries)
  • Re: SQL Server CE data transfer
    ... There is no direct way for you to send Excel data to a SQL CE database. ... you can convert it into an Access database, then you have a chance of ... > Users will download an excel file from our web site to a desktop computer ...
    (microsoft.public.pocketpc.developer)
  • RE: Macro
    ... Then post the query results. ... My data is in an Excel file called ... Microsoft SQL Server 2000, which requires a server, VBA or Microsoft Query ... VBA code in excel suddenly became un-compileable. ...
    (microsoft.public.excel.programming)
  • Re: Question for Joe Fallon--determining Data type
    ... then the data type for the column will be Text. ... means 255 characters max (that's a Jet limit). ... where MSDE or SQL Server is the main database (in these cases Jet ... Is 'Spreadsheet' an MS euphemism for 'Excel' or does it support other ...
    (microsoft.public.access.externaldata)