Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2005, 06:33 AM
Authorized User
 
Join Date: May 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel query retunrs error

Hi,

Help needed on the following:
I want to write a query in VB that combines data from a spreadsheet and an Access table.

conn.execute "SELECT * from 'spreadsheet.xls'"
returns an Error: Unrecognised DB format

Can anyone please help?

Regards,
Mihai

 
Old January 24th, 2005, 07:31 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

    With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y("ODBC;DSN=Excel Files;DBQ=C:\source.xls;DefaultDir=C:\"), Array(";DriverId=790;MaxBufferSize=2048;PageTimeou t=5;")), Destination:=Range("A1"))
        .CommandText = Array("SELECT F1, F2, F3, F4, F5 FROM data ")
        .Name = "Query from Excel Files"
        .FieldNames = True
        .Refresh BackgroundQuery:=False
    End With

replace the DBQ and Default locations in the code above with the location and filename of the source data.

Ensure that the table of data is defined with a name of somesorts otherwise it may not work.

Cheers

Matthew

 
Old January 24th, 2005, 08:00 AM
Authorized User
 
Join Date: May 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Matthew,

actually I have found the string for the connection (closer to your indication), using UDL to txt conversion.

"Provider=MSDASQL.1;Persist Security Info=False;Data Source=Excel Files;Mode=Share Deny None;Initial Catalog=workbook_name.xls"

Now I want to know if it is possible to join the table with an Access table. Can I work with 2 connections, or should I create 2 recordsets and then create another query based on the 2 recs?

Do you have another ideea?

Regards,
Mihai

 
Old January 24th, 2005, 02:23 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are using access, then I would recommend creating a linked connection into Access from your Excel file. You can then manipulate the joins in query to bring back a recordset.

In Excel you can then link to the query results and exen pass through from excel certain parameters from text boxes or drop down boxes that interact with the query and return only the records you need.

synopsis, I recommend you get Access to do the hard work.

Cheers

Matthew






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Using ADO to Query Excel alex_w Excel VBA 1 October 19th, 2006 04:42 AM
Using ADO to Query Excel alex_w Access VBA 1 May 18th, 2005 11:59 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.