Private Sub cmdCreate_Click()
Dim db_name As String
Dim password As String
Dim db As Database
Dim i As Integer
Dim txt As String
' Get the database name and password.
db_name = txtDbName.Text
password = txtPassword.Text
' Delete the database if it exists.
On Error Resume Next
Kill db_name
' Create the database.
On Error GoTo CreateError
Set db = DBEngine.CreateDatabase( _
db_name, dbLangGeneral & _
";pwd=" & password)
db.Close
Set db = Nothing
' Verify that we can open the database.
On Error GoTo OpenError
Set db = DBEngine.Workspaces(0).OpenDatabase( _
db_name, 0, 0, ";pwd=" & password)
' Read the table names.
For i = 0 To db.TableDefs.Count - 1
txt = txt & db.TableDefs(i).Name & vbCrLf
Next i
txtTables.Text = txt
db.Close
Set db = Nothing
Exit Sub
CreateError:
MsgBox "Error " & Format$(Err.Number) & _
" creating database '" & db_name & "'" & _
vbCrLf & Err.Description
Exit Sub
OpenError:
MsgBox "Error " & Format$(Err.Number) & _
" opening database '" & db_name & "'" & _
vbCrLf & Err.Description
Exit Sub
End Sub
|