• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1807
  • Last Modified:

Opening DBF files with VB6

What would be the procedure for opening a DBF file with VB6?
1 Solution
Open a recordset selecting the Microsoft OLE DB Simple Provider then especify the source (the folder) where the .DBF files are and that's all.

Obviously you have to write some SQL statement to read the data in this files.
Take a look here

Also, take a look to the help file :

Opens a specified database in a Workspace object and returns a reference to the Database object that represents it.


Set database = workspace.OpenDatabase (dbname, options, read-only, connect)

The OpenDatabase method syntax has these parts.

Part      Description
database      An object variable that represents the Database object that you want to open.
workspace      Optional. An object variable that represents the existing Workspace object that will contain the database. If you don't include a value for workspace, OpenDatabase uses the default workspace.
dbname      A String that is the name of an existing Microsoft Jet database file, or the data source name (DSN) of an ODBC data source. See the Name property for more information about setting this value.
options      Optional. A Variant that sets various options for the database, as specified in Settings.
read-only      Optional. A Variant (Boolean subtype) value that is True if you want to open the database with read-only access, or False (default) if you want to open the database with read/write access.
connect      Optional. A Variant (String subtype) that specifies various connection information, including passwords.

For Microsoft Jet workspaces, you can use the following values for the options argument.

Setting      Description
True      Opens the database in exclusive mode.
False      (Default) Opens the database in shared mode.
For ODBCDirect workspaces, the options argument determines if and when to prompt the user to establish the connection. You can use one of the following constants.

Constant      Description
dbDriverNoPrompt      The ODBC Driver Manager uses the connection string provided in dbname and connect. If you don't provide sufficient information, a run-time error occurs.
dbDriverPrompt      The ODBC Driver Manager displays the ODBC Data Sources dialog box, which displays any relevant information supplied in dbname or connect. The connection string is made up of the DSN that the user selects via the dialog boxes, or, if the user doesn't specify a DSN, the default DSN is used.
dbDriverComplete      (Default) If the connect and dbname arguments include all the necessary information to complete a connection, the ODBC Driver Manager uses the string in connect. Otherwise it behaves as it does when you specify dbDriverPrompt.
dbDriverCompleteRequired      This option behaves like dbDriverComplete except the ODBC driver disables the prompts for any information not required to complete the connection.

When you open a database, it is automatically added to the Databases collection. Further, in an ODBCDirect workspace, the Connection object corresponding to the new Database object is also created and appended to the Connections collection of the same Workspace object.
Some considerations apply when you use dbname:

·      If it refers to a database that is already open for exclusive access by another user, an error occurs.
·      If it doesn't refer to an existing database or valid ODBC data source name, an error occurs.
·      If it's a zero-length string ("") and connect is "ODBC;", a dialog box listing all registered ODBC data source names is displayed so the user can select a database.
·      If you're opening a database through an ODBCDirect workspace and you provide the DSN in connect, you can set dbname to a string of your choice that you can use to reference this database in subsequent code.

The connect argument is expressed in two parts: the database type, followed by a semicolon (;) and the optional arguments. You must first provide the database type, such as "ODBC;" or "FoxPro 2.5;". The optional arguments follow in no particular order, separated by semicolons. One of the parameters may be the password (if one is assigned). For example:

"FoxPro 2.5; pwd=mypassword"

Using the NewPassword method on a Database object other than an ODBCDirect database changes the password parameter that appears in the ";pwd=..." part of this argument. You must supply the options and read-only arguments to supply a source string. See the Connect property for syntax.

To close a database, and thus remove the Database object from the Databases collection, use the Close method on the object.

Note   When you access a Microsoft Jet-connected ODBC data source, you can improve your application's performance by opening a Database object connected to the ODBC data source, rather than by linking individual TableDef objects to specific tables in the ODBC data source.
bmullinsAuthor Commented:

I'm pretty new to Database programming.  I've increased the value to 250 points.

Can you give me a little more detail on how to do it?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Create an MS Access database and link the dbf file into it (File, Get External Data). Then you can access the file as if it were an Access table.
For instance Foxpro DBF and ADO

   ' use : Delete=Yes so deleted records are not included in Selects etc.

mcnn.Open "DSN=Visual FoxPro Tables;UID=;PWD=;" & _
"SourceDB=" & mstrDbDirectory & ";" & _
"SourceType=DBF;Exclusive=No;" & _
Here is what I use to open my database files:

Set oldws = DBEngine.Workspaces(0)
Set olddb = oldws.OpenDatabase("path\file")
Set newdyn = olddb.OpenRecordset("Select * from Table in db", dbOpenDynaset)

bmullinsAuthor Commented:
Which control would I add to the form to do this stuff?
Are you trying to do things right on the form or in the background?  I use that code to open my db and then add, read, etc.  I don't attach it to any control, I use code to display the information if I need to.
bmullinsAuthor Commented:
Set oldws = DBengine.workspaces(0) gives

"Object Required" Error
You need to check DAO 3.5 in the references section.

It is very simple, do u have any dbf based software in ur system.  If so, open 32bit odbc driver and configure ur driver to a dsn.

Open the database objects use either (ado or rdo), then
set the dsn to the corresponding name u assigned to it. And just go ahead.

Above answer is only if u have dbf softwares.

If u don't have it no problem, open the dbf files in the MSAcess and save it.

No ur file has been converted into MSacess format.  Follow the above procedure and get rid of ur problem
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now