1 1 1 1 1 1 1 1 1 1 Rating 5.00 (1 Vote)

Für 32Bit und 64Bit Office Versionen

Problemstellung:

Wie kann ich eine Neue Datenbank mittels ADO(X) erstellen?


Verweis auf die Microsoft ActiveX Data Objects 2.X Library erforderlich
Verweis auf die Microsoft ADO Ext. 2.X for DDL and Security Library erforderlich

Public Sub CreateNewADOX_DB(strDBPathName As String, Optional strPWD As String = "")
'*******************************************
'Name:      CreateNewADOX_DB   (Sub)
'Purpose:   erstellt ein neue DB mittels ADOX
'Author:    Tommyk
'Date:      März 02, 2004, 03:52:24
'Inputs:    strDBPathName=Name und Pfad der neuen DB,strPWD=DB-Passwort
'Output:
'*******************************************
On Error GoTo ErrHandler
Dim cat As New ADOX.Catalog
Dim strCat As String
    strCat = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPathName & ";"
    
    If strPWD = "" Then
        strCat = strCat
    Else
        strCat = strCat & "Jet OLEDB:Database Password=" & strPWD & ";"
    End If
    
    cat.Create strCat
    
Set cat = Nothing
ExitHere:
    Exit Sub
ErrHandler:
    Dim strErrString As String
    strErrString = "Error Information..." & vbCrLf
    strErrString = strErrString & "Error#: " & Err.Number & vbCrLf
    strErrString = strErrString & "Description: " & Err.Description
    MsgBox strErrString, vbCritical + vbOKOnly, "Error in Sub: CreateNewADOX_DB"
    Resume ExitHere
End Sub

Aufruf:

Call CreateNewADOX_DB("D:\Ado_2.mdb", "test")

 

Erstellt in im Ordner "D:\" eine neue DB "Ado_2.mdb" mit dem DB-Kennwort "test"

 

Ähnliche Artikel