Create a database programatically

  • Thread starter Thread starter OriginalStealth
  • Start date Start date
O

OriginalStealth

Form1 has cmdNewDbBtn and cboHQ. The On click event of
the cmdNewDbBtn needs to:

1. Create a new database.
2. The new db name needs to be the cboHQ.value. The new
db will have only one table in it called table1 which
will need to be exported and I can do that.

cboHQ.value = Atlanta

Thanks in advance!
OS
 
This example shows how to create a database using the DAO library.
It also demonstrates how ot turn off the properties that are likely to
corrupt the database.

Sub CreateDb()
Dim dbNew As DAO.Database
Dim prp As DAO.Property
Dim strFile As String

strFile = "C:\" & Me.cboHQ.Value
Set dbNew = DBEngine(0).CreateDatabase(strFile, dbLangGeneral)

With dbNew
Set prp = .CreateProperty("Perform Name AutoCorrect", dbLong, 0)
.Properties.Append prp
Set prp = .CreateProperty("Track Name AutoCorrect Info", _
dbLong, 0)
.Properties.Append prp
End With

dbNew.Close
Set prp = Nothing
Set dbNew = Nothing
Debug.Print "Created " & strFile
End Sub
 
Back
Top