Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Create .accde file on a machine that doesn't have Access

Hi

I am using the following VB.net code in my Excel Add-in  to create an Access
database. Certain of the users of my app will not have Access on their machines.
Will this sort of code be able to create a .accde file?

    Public Sub Create_Access()
        Dim P As String = "C:\Users\murbro\Documents\TestDB.accdb"
        If CreateAccessDatabase(P) = True Then
            MsgBox("Database Created")
        Else
            MsgBox("Database Creation Failed")
        End If
    End Sub


    Public Function CreateAccessDatabase( _
        ByVal DatabaseFullPath As String) As Boolean
        Dim bAns As Boolean
        Dim cat As New ADOX.Catalog()
        Try


            'Make sure the folder
            'provided in the path exists. If file name w/o path
            'is  specified,  the database will be created in your
            'application folder.

            Dim sCreateString As String
            sCreateString = _
              "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
               DatabaseFullPath
            cat.Create(sCreateString)

            bAns = True

        Catch Excep As System.Runtime.InteropServices.COMException
            bAns = False
            'do whatever else you need to do here, log,
            'msgbox etc.
        Finally
            cat = Nothing
        End Try
        Return bAns
    End Function
ASKER CERTIFIED SOLUTION
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much