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 June 15th, 2004, 05:33 AM
Authorized User
 
Join Date: Jun 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO connection string to dBase IV

Hi folks,
I'm trying to persuade Excel to send queries (SQL) to an approach dBase IV (.dbf) file. I've been wrestling with this for a while now, and haven't had any success.

I'm trying to modify the below method (which allows me to connect to another .xls file in the desired manner), but my attempts to modify it so that I can query the dbf have so far been unsuccessful.

Quote:
quote:Sub openCN(cn As ADODB.Connection)
  ' open connection and leave open
  Set cn = New ADODB.Connection
  cn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DriverId=790;ReadOnly=True;" & _
      "DBQ=" & datafile & ";" ' DriverId=790: Excel 97/2000
End Sub
So far so good. However... if I try
Quote:
quote:
Sub openDbfCN(cn As ADODB.Connection)
  'open connection to dbf and leave open
  Set cn = New ADODB.Connection
  cn.Open "DRIVER={Microsoft dBase Driver (*.dbf)};ReadOnly=True;" & _
      "DBQ=" & dbffile & ";"
End Sub
then I end up with "[Microsoft][ODBC dBase Driver]General error Unable to open registry key ‘Temporary (volatile) Jet DSN for process 0x1c0 Thread 0x4c0 DBC 0xd7d0064 Xbase’."

Also, if I try
Quote:
quote:
 Dim filedlg As FileDialog
    Set filedlg = Application.FileDialog(msoFileDialogOpen)
    filedlg.Title = "Please select the desired database"
    If filedlg.Show <> -1 Then Exit Sub 'user clicked cancel
    dbffile = filedlg.SelectedItems(1)


'create the connection string
szconnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & dbffile & ";" & _
            "Extended Properties=dBase IV;"

Set objConn = New ADODB.Connection
objConn.Open szconnect
It tells me the path is invalid, which leaves me even more confused.

Any help would be much appreciated.


Ed.
Ne auderis delere orbem rigidum meum!
__________________
Ed.
Ne auderis delere orbem rigidum meum!
 
Old June 20th, 2004, 06:34 AM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The DBQ or Data Source parameter needs to be a *path* and not filename.

See http://support.microsoft.com/default...b;en-us;326548

Hope this helps.
 
Old June 21st, 2004, 02:59 AM
Authorized User
 
Join Date: Jun 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, that's brilliant. Thanks mate, I've been looking for that answer for ages! I just knew it would be something simple I'd overlooked.

Ed.
Ne auderis delere orbem rigidum meum!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 12 connection to a dbase jardbf BOOK: Beginning ASP 3.0 1 May 25th, 2006 11:01 AM
connection to dbase jardbf Classic ASP Basics 0 May 23rd, 2006 04:10 AM
Read DBase IV file with other extension(.dbf) dieyoudie ASP.NET 1.0 and 1.1 Professional 1 January 9th, 2006 05:56 AM
SQL Server: Copy Table From dbase to other dbase orez SQL Server 2000 3 July 7th, 2004 03:51 AM
ADO Connection String jmss66 Classic ASP Basics 3 February 3rd, 2004 12:10 PM





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