Link to home
Start Free TrialLog in
Avatar of lbowers
lbowersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ODBC, DSNLess and a dBase database

I'm trying to open a DBF file via ODBC without using a DSN entry. Is this possible? Does anyone have any example code of how to achieve this? What should the connection string look like? I'm using DAO 3.51 and a dBase IV database. Thanks in advance...
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lbowers

ASKER

The above code works (thanks), but what is the ODBC connection string for dbf files? I notice that you don't actually specify a database within the DSN, just a directory. How do you tell VB the name of the database to use? I've tried loads of variations, but I keep gettings errors!
Since dBase is not a model of a table containing tables, the folder becomes like a database and the files (tables) are specified in your queries.
Avatar of lbowers

ASKER

Excellent - Thanks for your help. The points are yours, but I was wondering if you had ever come across the following problem before:

I am able to READ records via the ODBC connection, but I get an error whenever I attempt to DELETE, ADD or UPDATE records. I have set all "Read Only" properties to false. Any ideas?

Thanks again.
Show me your code.
Avatar of lbowers

ASKER

   Set ws = dao.CreateWorkspace("Workspace", "", "", dbUseODBC)
    Set db = ws.OpenConnection("Disk5Copy", dbDriverNoPrompt, False, "ODBC;")

sSQL = "DELETE FROM house" ' For example
db.Execute sSQL

I get "ODBC--call failed" error!
You need to add you DSN name somewhere:
Set db = ws.OpenConnection("Disk5Copy", dbDriverNoPrompt, False, "ODBC;DSN=MYDSN")
Avatar of lbowers

ASKER

Disk5Copy is my DSN. I find if I use "DSN=xxx" in the connections string, it doesn't work. Using the code I've show above, I can read records from the DBF file, I just can't ADD, DELETE or UPDATE! Hmmm...
Why don't you open the dBase file directly (without going through ODBC).

http://support.microsoft.com/support/kb/articles/Q240/7/48.ASP?LN=EN-US&SD=gn&FR=0