Create MS Access database

I am using the following code to create an MS Access database.  It creates the database but not the table.  It turns up a first chance exception of type 'System.Runtime.InteropServices.COMException'

Public Function CreateDatabase(ByVal DBFullPath As String, ByVal InitialTable As String) As Boolean
        'PURPOSE: Creates an access database, with one table.  The
        'table will have one numeric field, ID
        'PARAMETERS: DBFULLPATH: FileName/Path of database to create
        'InitialTable: Name of table to create
        'RETURNS: TRUE IF SUCCESSFUL, FALSE OTHERWISE

        Dim db As Database
        Dim td As New TableDef
        Dim ID As New Field
        Dim Juris As New Field
        Dim Month As New Field
        Dim Type As New Field
        Dim Count As New Field

        On Error GoTo ErrorHandler
        Dim engine As New DBEngine
        db = engine.CreateDatabase(DBFullPath, DAO.LanguageConstants.dbLangGeneral)
        td = db.CreateTableDef(InitialTable)

        'Optional for add a primary key field to Table
        Dim IDX As Index
        td.Fields.Append(td.CreateField("ID", ADOX.DataTypeEnum.adInteger))
        td.Fields("ID").Attributes = DAO.FieldAttributeEnum.dbAutoIncrField
        IDX = td.CreateIndex("IDXID")
        IDX.Fields.Append(td.CreateField("ID"))
        IDX.Primary = True
        td.Indexes.Append(IDX)

        ID = td.CreateField("ID", ADOX.DataTypeEnum.adInteger)
        Juris = td.CreateField("ID", ADOX.DataTypeEnum.adVarChar)
        Month = td.CreateField("ID", ADOX.DataTypeEnum.adDate)
        Type = td.CreateField("ID", ADOX.DataTypeEnum.adVarChar)
        Count = td.CreateField("ID", ADOX.DataTypeEnum.adInteger)

        td.Fields.Append(ID)
        td.Fields.Append(Juris)
        td.Fields.Append(Month)
        td.Fields.Append(Type)
        td.Fields.Append(Count)

        db.TableDefs.Append(td)

        CreateDatabase = True
ErrorHandler:
        If Not db Is Nothing Then db.Close()

    End Function

I call the function like this in the main form:

CreateDatabase("C:\Documents and Settings\Melissa Thomason\Desktop\GRASP\VA 1 .mdb", "Crime Data")

any help appreciated.  thanks!
SysCapstoneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

clockwatcherCommented:
Try this:

  Public Function CreateDatabase(ByVal DBFullPath As String, ByVal InitialTable As String) As Boolean
        'PURPOSE: Creates an access database, with one table.  The
        'table will have one numeric field, ID
        'PARAMETERS: DBFULLPATH: FileName/Path of database to create
        'InitialTable: Name of table to create
        'RETURNS: TRUE IF SUCCESSFUL, FALSE OTHERWISE

        Dim db As Database
        Dim td As New TableDef
        Dim ID As New Field
        Dim Juris As New Field
        Dim Month As New Field
        Dim Type As New Field
        Dim Count As New Field

        On Error GoTo ErrorHandler
        Dim engine As New DBEngine
        db = engine.CreateDatabase(DBFullPath, DAO.LanguageConstants.dbLangGeneral)
        td = db.CreateTableDef(InitialTable)

        'Optional for add a primary key field to Table
        Dim IDX As Index

        ID = td.CreateField("ID", DataTypeEnum.dbLong)
        ID.Attributes = DAO.FieldAttributeEnum.dbAutoIncrField
        td.Fields.Append(ID)

        Juris = td.CreateField("Juris", DataTypeEnum.dbText, 50)
        td.Fields.Append(Juris)

        Month = td.CreateField("Month", DataTypeEnum.dbDate)
        td.Fields.Append(Month)

        Type = td.CreateField("Type", DataTypeEnum.dbText, 50)
        td.Fields.Append(Type)

        Count = td.CreateField("Count", DataTypeEnum.dbInteger)
        td.Fields.Append(Count)

        IDX = td.CreateIndex("IDXID")
        IDX.Fields.Append(IDX.CreateField("ID"))
        IDX.Primary = True
        td.Indexes.Append(IDX)

        db.TableDefs.Append(td)

        CreateDatabase = True
ErrorHandler:
 
        If Not db Is Nothing Then db.Close()

    End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SysCapstoneAuthor Commented:
thank you so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.