Create Table Problem
30.10.2014 17:00:11
JoKu
ich will eine Nested Sets Struktur in einer DB über Excel-VBA aufbauen.
Hierzu habe ich ein "einfaches" SQL Statement, dass nicht über VBA funktioniert.
Immer bei dem Execute Kommando bekomme ich eine Syntax-Fehlermeldung.
Wer kann mir helfen, die Syntax für das SQL Statement zu korrigieren?
Private Sub CreateDatabase()
Dim dbConnectStr As String
Dim Catalog As Object
Dim cnt As ADODB.Connection
Dim dbPath As String
'Set database name here
UniqueName = "Test"
dbPath = "J:\Tree " & UniqueName & ".mdb"
dbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";"
'Create new database
Set Catalog = CreateObject("ADOX.Catalog")
Catalog.Create dbConnectStr
Set Catalog = Nothing
'Connect to database and insert a new table
Set cnt = New ADODB.Connection
With cnt
.Open dbConnectStr
SQLStr = "CREATE TABLE tree ( " & _
"[id] INT(12) UNSIGNED NOT NULL AUTO_INCREMENT, " & _
"[name] VARCHAR(50) NOT NULL, " & _
"[lft] INT(12) UNSIGNED NOT NULL, " & _
"[rgt] INT(12) UNSIGNED NOT NULL, " & _
"PRIMARY KEY (id), " & _
"key [lft] (lft), " & _
"key [rgt] (rgt) " & _
")"
.Execute SQLStr
End With
Set cnt = Nothing
End Sub