DanielLazarov
DanielLazarov

Reputation: 160

Open DBF file in MS access by name

I am making one form, where you enter a code. Using that code I get the exact Date of that record (e.g Code"100346" goes for record on 14.03.2013, and so on). When I have the record date, I have to open a DBF file (the actual record) with a name formed by the date. (e.g Date is 14.03.2013 and the file name will be N140313.DBF)

How can I program access to open/import that exact file, so I can work with it in access?

Upvotes: 2

Views: 4800

Answers (2)

HansUp
HansUp

Reputation: 97101

The answer may depend on how (what methods) you want to work with the DBF file, and I don't know what you have in mind there.

Perhaps you would be satisfied with a query to retrieve the DBF data. I have a dBase III file at this location: C:\Users\hans\Documents\F_NAMES.DBF

Then this query in Access 2007 gives me an editable result set ... meaning I can not just view but also alter the stored data.

SELECT *
FROM [dBase III;DATABASE=C:\Users\hans\Documents\].F_NAMES;

If you can create a similar query, you could use it as the record source for a form and view and edit your data in that form.

Upvotes: 2

donPablo
donPablo

Reputation: 1959

Here is a code fragment that I found googling... Its worth a try. I can't verify it because I have no DBF files...

    Dim cn As Object
    Dim rs As Object

    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")

    Dim oneSQL As String


    strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\;" & _
            "Extended Properties=dBASE IV;User ID=Admin;"

    ' works also
    'strCon = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=F:\;"

    cn.CursorLocation = adUseClient   ' allows you to see number of records returned

    cn.Open strCon

    oneSQL = "select * from [data.dbf];"      ' F:\data.dbf

    rs.Open oneSQL, cn, , , adCmdText

Upvotes: 0

Related Questions