Create Access Database via DAO

by Selva V Pasupathy

Option Explicit
Private myMdbPath As String
Private myMDB As Database
Private myTableDef As TableDef
Private myIndex As DAO.Index

Sub Create_MDB()
    myMdbPath = ThisWorkbook.Path & "\" & _
                                myMDBName & ".mdb"
    If Dir(myMdbPath)  "" Then Kill myMdbPath

    Set myMDB = CreateDatabase(myMdbPath, dbLangGeneral)

    Set myTableDef = myMDB.CreateTableDef(MyTable)

    With myTableDef
        .Fields.Append .CreateField("ID", dbLong, 4)
        .Fields.Append .CreateField("ACCT", dbText, 14)
   .Fields.Append .CreateField("CII", dbText, 14)
   .Fields.Append .CreateField("STATUS", dbText)
   .Fields.Append .CreateField("DECISION", dbText)
   .Fields.Append .CreateField("RACF", dbText)
   .Fields.Append .CreateField("CONTRACTDATE", dbDate)
   .Fields.Append .CreateField("RECEIPTDATE", dbDate)
   .Fields.Append .CreateField("FOLLOWUPDATE", dbDate)
   .Fields.Append .CreateField("FOLLOWUP_N1", dbText)
   .Fields.Append .CreateField("FOLLOWUP_N2", dbText)
   .Fields.Append .CreateField("DECLIFE", dbText)
   .Fields.Append .CreateField("DECDIS", dbText)
   .Fields.Append .CreateField("REASON", dbText)
   .Fields.Append .CreateField("FIRSTNAME", dbText)
   .Fields.Append .CreateField("LASTNAME", dbText)
   .Fields.Append .CreateField("ADDLINE1", dbText)
   .Fields.Append .CreateField("ADDLINE2", dbText)
   .Fields.Append .CreateField("CITY", dbText)
   .Fields.Append .CreateField("ST", dbText, 2)
   .Fields.Append .CreateField("ZIP", dbText, 5)

   myTableDef("ID").Attributes = dbAutoIncrField

   Set myIndex = .CreateIndex("ACCT")
   myIndex.Fields.Append myIndex.CreateField("ID", dbLong)

        myIndex.Primary = True
        .Indexes.Append myIndex
    End With

    ' Save Table info
    myMDB.TableDefs.Append myTableDef
    myMDB.Close
End Sub

Private Function myMDBName()
myMDBName = Application.InputBox("Give " &amp: _
     the name of the " & _
     "Access file you want to be saved. ")
End Function
Private Function MyTable()
    MyTable = Application.InputBox("Give " & _
     the name of the " & _
     "Table you want in MDB file. ")
End Function

For more on Resources, Downloads, &
Tutorials visit following pages
http://selvavinaygam.googlepages.com
http://socko.350.com

For Feedback and/or comments, please mail me at
s o c k o (at) r e d i f f m a i l (dot) c o m

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: