Error Exporting Access Query Results to Excel

I'm having 2 different problems exporting query results from Access to Excel 
(Office 2007).

Problem 1:

I do what I've always done, in Access VBA get ADO recordset from query 
results, instantiate Excel, get a range object, use the range object's 
CopyFromRecordset method.  This has always worked in the (pre-Office 2007) 
past for me.  It is much easier than iterating records and columns and 
assigning values to cells.  Now, I get an error -2147467259 Automation Error 
Unspecified Error.  I'm guessing this is because 2 of my recordset fields are 
pictures in Attachment type fields, which I've never used.  I'm guessing 
Excel doesn't like this field type in the CopyFromRecordset.

Problem 2:

I tried to mitigate problem 1 by modifying the query to not include the 
Attachment fields.  This is totally not working.

I'll start by describing my database. I'm using a template supplied by 
Access for the Contacts database.  I created my database, then added various 
fields to the contacts table.  The query I'm using is called "Contacts 
Extended", which has a custom field, "Send To", which is the result of an IIf 
statement which tests other column values and uses them if non-null.  The 
query basically says "Select [Send To], Contacts.* From Contacts Order By..."

This query of course returns all of the fields in the table plus one extra, 
and causes problem 1 above.

I make a new query called "Contact List", which says "Select [Send To], 
Contacts.Name, Contacts.Address, ... etc. From Contacts Order By...".  Both 
queries work perfectly fine in Access.  In VBA code, I do the following:

Dim oRS As ADODB.Recordset
oRS.Open "[Contacts Extended]", CurrentProject.Connection, adOpenStatic, 
adLockReadOnly

The above query works, but gives me problem 1 adding it to the worksheet in 
Excel.

If I replace the query name above with "[Contact List]" and execute the 
code, I get:

Run-time error '-2147217900 (80040e14)':
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 
'UPDATE'.

No matter what fields I put in the query (including all fields), this 
happens.  On the query which selects [Send To], Contacts.* everything works 
fine.

What is the deal here?  Any ideas?

Thanks...
-- 
Ron Mittelman
0
Utf
5/4/2010 10:46:01 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

1 Replies
817 Views

Similar Articles

[PageSpeed] 16

My guess is that the SQL statement you are trying to use for the second 
query (the subset) is not properly formatted / has bad syntax; or something 
in the SQL statement is being incorrectly read/interpreted by the recordset 
call in VBA code.

Open your Contact List query in SQL mode, and copy the full SQL statement. 
Paste it into a reply to this thread; let's see if it may contain something 
that would error in ADO recordset.
-- 

        Ken Snell
http://www.accessmvp.com/KDSnell/




"Ron Mittelman" <RonMittelman@discussions.microsoft.com> wrote in message 
news:BEF705C1-639E-4502-B9B7-494B9373B2AA@microsoft.com...
> I'm having 2 different problems exporting query results from Access to 
> Excel
> (Office 2007).
>
> Problem 1:
>
> I do what I've always done, in Access VBA get ADO recordset from query
> results, instantiate Excel, get a range object, use the range object's
> CopyFromRecordset method.  This has always worked in the (pre-Office 2007)
> past for me.  It is much easier than iterating records and columns and
> assigning values to cells.  Now, I get an error -2147467259 Automation 
> Error
> Unspecified Error.  I'm guessing this is because 2 of my recordset fields 
> are
> pictures in Attachment type fields, which I've never used.  I'm guessing
> Excel doesn't like this field type in the CopyFromRecordset.
>
> Problem 2:
>
> I tried to mitigate problem 1 by modifying the query to not include the
> Attachment fields.  This is totally not working.
>
> I'll start by describing my database. I'm using a template supplied by
> Access for the Contacts database.  I created my database, then added 
> various
> fields to the contacts table.  The query I'm using is called "Contacts
> Extended", which has a custom field, "Send To", which is the result of an 
> IIf
> statement which tests other column values and uses them if non-null.  The
> query basically says "Select [Send To], Contacts.* From Contacts Order 
> By..."
>
> This query of course returns all of the fields in the table plus one 
> extra,
> and causes problem 1 above.
>
> I make a new query called "Contact List", which says "Select [Send To],
> Contacts.Name, Contacts.Address, ... etc. From Contacts Order By...". 
> Both
> queries work perfectly fine in Access.  In VBA code, I do the following:
>
> Dim oRS As ADODB.Recordset
> oRS.Open "[Contacts Extended]", CurrentProject.Connection, adOpenStatic,
> adLockReadOnly
>
> The above query works, but gives me problem 1 adding it to the worksheet 
> in
> Excel.
>
> If I replace the query name above with "[Contact List]" and execute the
> code, I get:
>
> Run-time error '-2147217900 (80040e14)':
> Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' 
> or
> 'UPDATE'.
>
> No matter what fields I put in the query (including all fields), this
> happens.  On the query which selects [Send To], Contacts.* everything 
> works
> fine.
>
> What is the deal here?  Any ideas?
>
> Thanks...
> -- 
> Ron Mittelman 


0
Ken
5/7/2010 3:37:53 PM
Reply:

Similar Artilces:

Reporting from Project Server
I dont know if i need to ask this question here or in the Access section. I have an ODBC connection to the Project Server database so I can make reports through Access. Access' limit of 255 fields per table is causing me some trouble. for example, the MSP_VIEW_PROJ_PROJECTS_ENT table has well over 255 fields. Access only shows me the first 255 fields. how can I change that so I can see all the fields in that table? thanks, Hadi Hadi, I have not tried this yet it may be a viable option. Have your DBA create a view that pulls the key fields to this table and the specifi...

New to excel
Hi All, I'm new to Excel ( and to this forum :) ) and so I hope somebody may b able to help me. I've got 2 questions.... QUESTION 1 I've got a spreadsheet which takes data from one worksheet and uses i to calculate data in a second worksheet using the following code formula: =IF('4th November 2005'!B19="","nothing here dude",IF(B19<'4th Novembe 2005'!B19,"UP",IF(B19='4th November 2005'!B19,"Same",IF(B19>'4t November 2005'!B19,"DOWN")))) The problem is, when I create a new worksheet I have...

Looking for Excel Help
I'm a very novice Excel user and am looking for a little help with creating a formula for a spreadsheet I'm creating for my personal use. I would appreciate some assistance if possible. Thanks in advance. Dan --- Message posted from http://www.ExcelForum.com/ Hi Dan! Post a sample of what you want to do. Your question is just a tad open ended <g> -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. "DanB4105" <DanB4105.ywtpa@excelfor...

Outlook 0x800ccc0d error when Norton e-mail protect enabled: see hosts
This post is made to help others solve this issue, based on my experience. Symptom: - Outlook works perfectly well when Norton Anti-Virus e-mail protection is disabled - Outlook cannot retrieve incoming messages when NAV e-mail protection is enabled, message being: pop3 server not found, error 0x800ccc0d This symptom, and possible solutions, are exactly the object of Symantec support note: http://service1.symantec.com/SUPPORT/nav.nsf/docid/2000020716064206 Please read this note first ! The object of this post is to add another possible solution to this problem. NAV email protection sets up...

Excel button problem
Hi All I have a macro that copies a worksheet in the active workbook and puts it into a new workbook - then formats it and deletes any buttons on the worksheet. On the first click on the button the macro works ok. On the second click, it fails because the all assigned macros on all buttons in the active workbook changed from "mba" to "book1!mba". Book 1 doesn't exists (wasn't opened, wasn't saved, doesn't have the macros). I've never experienced this problem before?? Can anyone help to solve this problem? FYI The macro to do this is c...

Excel 97 #9
Please can anyone help??? I have two columns in Excel 97. The first contains a list of statu values eg. pending, or granted or withdrawn. The second contains date eg.01/12/1997, 05/06/2003. I woudl like to know how to get all th granted apps before 31/12/2003. Can anyone help please -- Message posted from http://www.ExcelForum.com theres many ways, but an easiest way would be to do a sort. Highlight the 2 columns, click on data, then sort, then sort by status, then by date. this should group them all together. hope this helps...toe >-----Original Message----- >Please can anyo...

learning Excel #3
Hi, I was considering learning Excel as an additional tool for my data analysis work. Is it better to use data sets that I have previously used with SPSS and apply the same analysis tools as in SPSS? For applying the appropriate tools, I was considering using excel's online help. The second option I have is to use some excel book for data analysis and apply the techniques to data sets provided with the book. Any suggestions????? regards Metal ...

Unknown error from CFtpConnection::GetFile()...
Hi all, I'm having intermittent problems with CFtpConnection::GetFile()... 99% of the time GetFile() succeeds but occasionally it fails and returns FALSE with a GetLastError of 0x2EFF (12031) which I can't find documented/defined anywhere... Anyone know what this error means...? Where it is defined...? A bit of searching on on the web seems to suggest; "The connection with the server has been reset." Can anyone confirm this...? Many thanks, Andy. Andrew Kilgore wrote: > Hi all, > > I'm having intermittent problems with CFtpConnection::GetFile()... > 99%...

Error 550 Relaying denied
I get this nearly every time I try to send information using MS Outlook email. Any suggestions? You probably need to turn on authentication to your outgoing server. You can do so on the "Outgoing Server" tab for your mail account. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:9cf101c3eacf$a3250cb0$a401280a@phx.gbl, Dick Brenneke wrote: > I get this nearly every time I try to send information > using MS Outlook email. Any suggestions? Th...

How do I Remove a Split from my Comments in Excel 2003? #2
I have set my current workbook to split/freeze the first column and first 2 rows. Now, when I add a comment to the second row (in any column) my comments are cut off if I should scroll down. I don't ever remember the behavior before. And I don't know what I've done to enable it but it's really annoying. How do turn this off ? ...

unable to paste Excel 2003 chart into Outlook 2003
(This was posted on "excel.charting" group.) I have a user who's unable to paste an Excel 2003 chart into Outlook 2003 email message. In Outlook options, the checkbox is selected for "Use Microsoft Office Word 2003 to edit e-mail messages". When I tested this on my own computer running the same version of Office, if the box is check, I have no problem pasting; if this box is cleared, I cannot paste. But on his computer, it doesn't work regardless. Thanks and regards, TL ...

nested OR in queries
I have a table that has 20 date fields for each record. I need to select any record that has a matching date in at least one of those fields so it becomes a huge OR in a query and I have noticed that I am limited to 9 in a query. Is there a way to do this efficiently or will I need multiple queries to test all 20 date fields? If your table uses multiple date fields, the first thing you'll want to consider is coming up with a new table! In a spreadsheet, adding 20 date fields may be the only way to handle a situation, but you won't get the best use of Access' features and funct...

get a result of an sql into a field
Hi there I would like to get a result of an sql execution (ms sql server) into aq filed. example i A1 I have a ID number in A2 I would like to get the result of something like this 'select name from address where id=A1' Does this exist in Excel ? Thanks in advance Ralf Here is the sub i have written for loading an Sql Query into th worksheet. Parameters: Server Name DataBase Name SQL Command Target Sheet name Column to begin from Row to begin from ex: CALL LoadData("MyServer","MyDataBase","Select UserName fro TblNames", "QueryData"...

CSV Files and VLOOKUP error
Does anyone know why VLOOKUP and Compare formulas don't work o information originating from a CSV file? I've tried copying an pasting values only (to leave behind any formatting), but it doesn' help. Through countless tests, I've narrowed it down to the CSV file bein the only possible cause -- Message posted from http://www.ExcelForum.com Hi ajpowers, Just a guess but the imported data may have leading or trailing spaces or are numbers stored as text. You could use the formula =A1=D1 to see if you get a true or false, where A1 is the lookup value and D1 ia the CVS valu...

Uninstall of mappoint has caused errors with excel
Hi, I am running Office 2003 on the terminal server (windows 2003) and had a copy of mappoint as well. This is a mapping program. We ininstalled mappoint which has caused an error message with Excel and other office products. The error says "Cd:\documents and settings\administrator.ocrdc1\application data\microsoft\addins c:\Program files\common files\microsoft shared\geography\mpoai9.dll is not a valid add-in." I then click OK and excel opens up and everything is fine. The problem is that we are using other programs as well such as Quickbooks that export to excel and t...

Document Viewer installer error
I recently ran CHKDSK /F as this was prompted when I attempted to run defrag etc. Since the chkdsk was run, when I turn my PC on, I receive the following message: "document viewier - installed encountered an unexpected error - error code 2908". I click run, the same error just repeats and loops. The only was I can remove it is to end task via task manager. Any ideas how I can correct this error? many thanks ...

Excel corrupts when asking to update vlookups
We are experiencing weird behavior with some Office 2K3 Excel spreadsheets that contain lots of calculations, but no macros. On some pc’s Excel acts normally, on others you get the error. I have a couple of screen shots available. Any help is appreciated. If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the subject line 3. You send a clear explanation of what you want 4. You send before/after examples and expected results. -- Don Gu...

Cannot open Outlook, keep getting Send error report of Microsoft.
We are having problems with Outlook 2003. Everytime we try to open, we get this: Send error report to Microsoft. Any ideas why? All windows and office update have been completed. ...

Error 130
Hope someone can point me in the right direction. OSX 10.63, MacOffice 2008 12.2.4 When I try to connect to the following news server ( that doesn't require a user name or password ) I get the following error when attempting to download the List of Newsgroups: "Too many connections in your class - Could not receive the Newsgroup List - ERROR 130 " Any pointers much appreciated. Using Msnews servers works fine. -- Welsh Gas Remove usual to reply direct. paulatwoodsforddotcodotuk On 4/27/10 10:49 PM, in article 59bb7979.-1@webcrossing.JaKIaxP2ac0, "We...

Access to User Calendar
I have a user called small conference room that is used to schedule meetings on its calendar. I would like to link the calendar from our intranet site to the calendar with a UNC path. I am calling outlook: and I can get to my local mailbox and public folders but I am unable to connect to another users calendar. I am running Exchange 2003 and Outlook 2003. Is there some security modifications that need to be done? Any help is appreciated. Thanks, Steve I believe that you will need full mailbox rights. -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!&...

I need to print a word in PDF from excel.
Hi, In my excel Macro, I update several values and then open a word linked with that excel. Finally what I need to do is to print that word to PDF. I already have a PDF Printer, so I just need the code to do it. Can anybody help me? Thanks in advance. Gast=F3n. Habilita la impresora predeterminada como la PDF y ya lo puedes imprimir a al formato deseado Gracias Francisco,=20 Tienes alg=FAn codigo para ello? gracias Repitiendo: Desde el panel de impresoras asigno primero la que me interesa y despues ejecuto mi macro desde el archivo excel asignando la instruccion sig: midefaultes = a...

q Emailing Excel Sheet With Outlook
I am trying to send a table from Excel within the body of an Outlook (lastest versions) to be sent as a fax. Am able to do this, BUT when the document prints out on the fax machine the formating is off (too big for the sheet). I am flexible on changing the method I send it to the fax machine, however it must be sent to the fax via macro. Below is the code I am using. Any help would be greatly appreciated. David Public Sub DoIt() 'On Error GoTo Handler Dim EmailAddress(0 To 2) As String Dim Count As Integer Dim N As Integer Dim sRec1(0) As String Dim sRec2(0 To 1) As...

How do I get Excell to sort dates that range from 1800 to 1900's
I have posted a cemetery survey on Excell spreadsheet. When I try to sort the birth dates or death dates in ascending or descending order the range of 1900 dates will sort but the 1800 dates fall after the 1900 and will not sort. Why? Is this inherit with this program? The WinXL default dates start with 31 December 1899, so earlier "dates" are interpreted as Text. You can use helper columns and text functions (LEFT(),RIGHT(),MID()) to put the Year, Month and Day in separate columns, then sort. Take a look here for additional workarounds: http://j-walk.com/ss/excel/files...

how do I add error bars to a 3D chart in excel?
The help states you can only add error bars to data series in 2D area. Is there a way to add them to a 3D chart? Hi, I would not have thought so. Obviously as it is not a built-in option the only way would be a work around perhaps using dummy series. Unfortunately you can create 3d combination charts. Stick with the 2d view. Cheers Andy elahe wrote: > The help states you can only add error bars to data series in 2D area. Is > there a way to add them to a 3D chart? -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info I checked, and error bars are not offered for 3D ch...

microsoft.public.access.conversion
...