MS Access developer
How to Connect Access Database Using DAO in VB.NET
![]() |
VB.NET DAO |
Data Access Object (DAO)
According to Microsoft Docs, Conversion from DAO TO ADO: Versions of the DAO library prior to 3.6 are not provided or supported in Access.
Also:
ODBC Direct workspaces are not supported in Microsoft Access 2013. Use ADO if you want to access external Data sources without using the Microsoft Access database engine.
DAO is used with Access databases and is supported through MS Office 2013. DAO 3.6 is the final version, and it is considered obsolete.
These classes work with other application framework classes to provide easy access to DAO databases, which use the same database engine as Microsoft Visual Basic and Microsoft Access.
The DAO classes can also access a wide variety of databases for which Open Database Connectivity (ODBC) drivers are available.
Programs that use DAO databases will have at least a CDaoDatabase object and a CDaoRecordset object.
DAO 361
- DAO : Data Access Object Version 3.60
- Path: C:\WINDOWS\assembly\GAC\dao\
VB.NET Project Design
- Create a new Visual Basic project – WinForms
- Create a new MS Access 2003 Database (Name: ahmed.mdb)
- New form (Name: Form1)
- Add Reference: COM ⇒ DAO 3.61
Code Example
Imports DAO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim DB As DAO.Database
Dim DBE As New DAO.DBEngine
DB = DBE.OpenDatabase("ahmed.mdb", Nothing, False, "dbase iv;")
End Sub
End Class
And you have just connected your database *.mdb
in VB.NET using DAO 3.61.
Using DAO360 with Microsoft Access 2007/2010/2013/2019 (*.accdb)
1) How to Get All Tables in a Database using DAO360
- Create a VB.NET WinForms Project
- Add a Module [DaoConnection]
- Add Reference to DAO360
- Create an MS Access Database 2007/2010/2013/2019 (db.accdb) in C:\Databases\
- Encrypt Database [db.accdb] with Password (MyPassword)
2) How to Get All Fields in a Database using DAO360
Using the above example, this code will enumerate the Tables → Fields → Attributes.
Code Reference:
Imports dao
Module DaoConnection
Public Sub ConnectAsDAO()
Dim Attrib As String
Dim prpLoop As dao.Property
Dim DBEngin As New Microsoft.Office.Interop.Access.Dao.DBEngine
Dim wrkMain As Microsoft.Office.Interop.Access.Dao.Workspace = DBEngin.Workspaces(0)
Dim dbsPubs As Database = _
wrkMain.OpenDatabase("C:\Databases\db.accdb", False, False, ";pwd=MyPassword")
Dim tBldef As TableDef
For I As Integer = 0 To dbsPubs.TableDefs.Count - 1
tBldef = dbsPubs.TableDefs(I)
Attrib = (tBldef.Attributes And -2147483646)
If Attrib = 0 Then
For Each prpLoop In tBldef.Properties
Try
Debug.WriteLine(" " & prpLoop.Name & " - " &
IIf(IsNothing(prpLoop), "[empty]", prpLoop.Value))
Catch ex As Exception
Debug.WriteLine(prpLoop.Name)
End Try
Next
'Debug.WriteLine(tBldef.Name)
Dim fldLoop As Fields = tBldef.Fields
For Each fldloop1 As dao.Field In fldLoop
Debug.WriteLine("Table::" & tBldef.Name & "::Field::" & fldloop1.Name)
Next
End If
Next
dbsPubs = Nothing
tBldef = Nothing
DBEngin = Nothing
End Module
⭐ Visit My GitHub Gist
♥ Here are some online Visual Basic lessons and courses: