For a start, you can do this with some controls. Later on, you can do this by writing some code instead of using controls.
The following example will show the content of your database in a Grid control and you will be able to manipulate the content of your database from VB.
Steps:
Add 1 Data-control to your form
The “Properties” for this control:
- Connect = “Acces” (if your database has the extension .mdb)
- DatabasName = The location of your database
- RecordsetType = “Dynaset” (Enables you to manipulate your database from VB)
- RecordSource = The name of a table from your database
Now add the following control to your Form:
“Microsoft Data Bound Grid Control 5.0 (DBgrid32.ocx)”
The “Properties” for this control:
- DataSource = The name of your Data-control
Right-click at your DBGrid-control (on the Form) and a dropdown menu appears.
Select “Retrieve Fields”
That’s it.
The following example shows all the records in a table called Table1, where “Month” = 3
Data1.RecordSource = "Select * from Table1 where Month = 3'"
Data1.Refresh
To show all the content of your database again:
Data1.RecordSource = "Select * from Table1"
Data1.Refresh
Read more about using SQL in the help-file in “Microsoft Access”.
If you want to use your database without using Controls, then try this link:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.