AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Wednesday, June 06, 2007

How to get reference to DBEngine.

Once you need to write a program or addin, which works with installed version of DAO, it can be DAO 3.5, 3.6 or 12 (Access 2007). So you need to use late binding and get reference to latest version of DAO. Simple CreateObject("DAO.DBEngine") will not work. Here a function, which do this task:

Public Function GetDBEngine() As Object

On Error Resume Next

'try 120

Set GetDBEngine = CreateObject("DAO.DBEngine.120")

If Err.Number <> 0 Then

'try 36

Err.Clear

Set GetDBEngine = CreateObject("DAO.DBEngine.36")

If Err.Number <> 0 Then

Set GetDBEngine = CreateObject("DAO.DBEngine.35")

End If

End If

End Function


 


Technorati tags: , ,

1 Comments:

Blogger Derek said...

Thanks Alex! Not many web pages are mentioning the '120' version - you helped me a lot with that one!

8:13 AM  

Post a Comment

<< Home