AccessBlog.net

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

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Friday, July 27, 2007

How to create Access 2002-2003 mdb in code

Doug Steele, Access MVP, has recently pointed to this conversation, discussing how to create Access mdb file in 2002-2003 format. The problem that dbEngine.CreateDatabase method can only create 2000 file format, which is equal to 2002-2003 format from Jet point of view, but not for Access. The trick is to set default file format in Access to 2002-2003 using SetOption method and then create mdb in Access using NewCurrentDatabase method. Below I posting routine from mentioned thread, just in case Google "forgets" it.

Private Sub CreateMDB2()

On Error GoTo ErrHandler

Dim oApp As Access.Application

Dim sFile As String, sDFF As String

Dim sSetting As String

'sSetting represents clicking on menu Options in Access

sSetting = "Default File Format"

Set oApp = New Access.Application

sDFF = oApp.GetOption(sSetting)

Call oApp.SetOption(sSetting, "10")

'9 is 2K mdb, 10 is XP mdb

sFile = CurrentProject.Path & "\Test.mdb"

Call oApp.NewCurrentDatabase(sFile)

Call oApp.SetOption(sSetting, sDFF)

ExitHandler:

If (oApp Is Nothing) Then

'skip

Else

Set oApp = Nothing

End If

Exit Sub

ErrHandler:

MsgBox Err.Number & vbCrLf & Err.Description

Resume ExitHandler

End Sub



Technorati tags: , ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home