Databases are very useful, and indeed very popular. Visual Basic has a number of things that let you access databases very easily.
VB comes with the "Visual Data Manager" (a.k.a. VisData), which you can run from the Add-Ins menu. VisData lets you create and view databases in a variety of formats, include Access (2.0 and 97), Paradox, FoxPro, and Oracle. Visual Basic itself includes the Data control, which serves as a convenient link to a database.
With these tools, you won't have to write a single line of code to create a convenient interface to any database!
Visual Data Manager
To use VisData, click the Add-Ins menu and select Visual Data Manager. When VisData appears, select the New menu and choose your favorite format. Type in a name and hit OK, and a new database will be created with that name.
Once you've created your database file, two windows will appear: the Database Window and the SQL Statement window. To add a new table to your database, right-click anywhere in the Database Window and select New Table. You'll then be guided through the process of creating a new table and adding fields to it.
Once you've created your table, you can double-click on its name in the Database Window to open up a window that serves as a "short and sweet" interface to that table; you can add new records, delete records, etc.
The Data Control
Now that you've created a database, you can return to Visual Basic and use the Data control. The Data control has three important properties:
A Data control's DatabaseName
property is just the name of your database file. When you "point" that property correctly, you'll have a link to that database.
Next we have the RecordSource
property, this is just the name of the table you want to access in your database.
The third property of interest is the EOFAction
property, which simply specifies what to do when the user goes to the last record in the table. I recommend setting this to "2 - Add New"
, which will allow the user to add new records to the end of the table, if s/he moves to the final record.
The Other Controls
Every text-based control (TextBoxes, ComboBoxes) have two very interesting properties: The DataSource
and the DataField
properties. The DataSource
property can be set to the name of a Data control (creating a "link" to that control, and through that control to the database). The RecordField
property is just the name of the field that you want your TextBox or ComboBox or whatever to correspond to.
When you establish all these "links" and start your program, the first record in the table you specified in your database will be displayed in the appropriate text boxes in your program! The Data control will let users move back and forth between records, and if they move to the end they'll get a blank record, in which they can add a record (as soon as it's added another blank record will be created after it).
It's that simple.
Above and Beyond
From here you can add more Data controls, pointing them to other tables in the database, or even to other databases. You can also add code to do a variety of things with your records (deleting them, for example). There's also a collection of database controls (DBCombo, DBList) that allow more powerful access to databases.
Visual Basic also comes with a program called Crystal Reports Pro, which basically lets you create MS Access-style reports, with an interface very similar to Access.