?
Solved

INCORRECT ADO CONNECTION STRING FROM VISUAL BASIC (MSACCESS)

Posted on 2004-09-01
5
Medium Priority
?
217 Views
Last Modified: 2013-11-25
I am trying to open an EXCEL file into an ADO Recordset from Access like so :

    Set db = New ADODB.Connection
    Set rs = New ADODB.Recordset
   
    db.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
           "DriverId=790;" & _
           "Dbq=" & CurrentProject.Path & "\" & mFilename & ".xls;" & _
           "DefaultDir=" & CurrentProject.Path
     
    Call rs.Open("SELECT * FROM " & mFilename, db, adOpenStatic, adLockReadOnly)

This doesn't work, any idea what the syntax is like??
0
Comment
Question by:const71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 11959416
See:
http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSNLess.htm#ODBCDriverForExcel

what's the CurrentProject.Path returned? I suspect your path returned may be wrong? how about using app.path ?
0
 

Author Comment

by:const71
ID: 11959829
this is MSAccess. The problem is with the SELECT statement
0
 
LVL 18

Accepted Solution

by:
Sethi earned 2000 total points
ID: 11960102
Use the following:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
 
"HDR=Yes;" indicates that the first row contains columnnames, not data
"IMEX=1;" tells the driver to always read "intermixed" data columns as text

TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
0
 

Author Comment

by:const71
ID: 11966698
Beautiful..Works like a charm!! Thanks
0
 
LVL 18

Expert Comment

by:Sethi
ID: 11969336
:-) Anytime
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question