This project has moved and is read-only. For the latest updates, please go here.
' create a new database with Access
' taken from Example01.vb

Private Sub Example01Main()

   ' start access 
   Dim accessApplication As New Access.Application()

   'create database name 
   Dim fileExtension As String = GetDefaultExtension(accessApplication)
   Dim documentFile As String = String.Format("{0}\\Example01{1}", 
Application.StartupPath,
fileExtension) 'delete old database if exists If (System.IO.File.Exists(documentFile)) Then System.IO.File.Delete(documentFile) End If ' create database Dim newDatabase As DAO.Database =
accessApplication.DBEngine.Workspaces(0).CreateDatabase(
documentFile, LanguageConstants.dbLangGeneral) 'close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll) accessApplication.Dispose() Dim fDialog As New FinishDialog("Database saved.", documentFile) fDialog.ShowDialog(Me) End Sub ''' <summary> ''' returns the valid file extension for the instance. for example ".mdb" or ".accdb" ''' </summary> ''' <param name="application">the instance</param> ''' <returns>the extension</returns> ''' <remarks></remarks> Private Function GetDefaultExtension(ByVal application As Access.Application) As String ' Access 2000 doesnt have the Version property(unfortunately) ' we check for support with the SupportEntity method, implemented by NetOffice If (Not application.EntityIsAvailable("Version")) Then Return ".mdb" End If Dim version As Double = _
Convert.ToDouble(application.Version, CultureInfo.InvariantCulture)
If (version >= 12.0) Then Return ".accdb" Else Return ".xls" End If End Function

Last edited Jun 13, 2012 at 2:50 PM by SebastianDotNet, version 4

Comments

No comments yet.