Results 1 to 6 of 6

Thread: creating a new database at runtime

  1. #1
    Guest

    Post

    Is there a way i can design a new access database during runtime if there is not one already existing?

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    DAO or ADO?

  3. #3
    Guest

    Post

    im not sure, does that matter?

  4. #4
    New Member
    Join Date
    Jan 2000
    Posts
    1

    Post

    I don't know if this is the best way but it works for me:

    Public Function CreateDB()

    'create variables for number of fields needed
    Dim F1 As Field, F2 As Field, F3 As Field

    'Create Database Object variable
    Dim myWs as Workspace
    Dim myDB as Database

    'Create TableDef object
    Dim myTbl as TableDef

    'Create Database
    Set myWs = DBEngine.Workspaces(0)
    Set myDb=myWs.CreateDatabase("C:\EMP.MDB", dbLangGeneral)

    'Create Table
    Set myTbl = myDb.CreateTableDef("EMPLOYEE")

    'Set Field Properties
    Set F1=myTbl.CreateField("LNAME", dbText, 30)
    ' set flag if needed such as:
    F1.AllowZeroLength = False
    Set F2=myTbl.CreateField("FNAME", dbText,15)
    F2.AllowZeroLength = False
    Set F3=myTbl.CreateField("SSN", dbText, 11)
    F3.AllowZeroLength = False

    'Append Fields to Table definition
    myTbl.Fields.Append F1
    myTbl.Fields.Append F2
    myTbl.Fields.Append F3

    'Append Table to Database
    myDb.TableDefs.Append myTbl

    myDb.Close

    End Function


    You'll probable use variables where I hardcoded the database path and name.
    You also must remember to delete the database before it is created again.

    Good Luck

    [This message has been edited by bullwhip (edited 01-20-2000).]

    [This message has been edited by bullwhip (edited 01-20-2000).]

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    There ya go! Thanks bullwhip.

    dmartin -- It does matter which data access method you are using so we can provide the appropriate example. In this case, I hope you like DAO because you got lots of it!

  6. #6
    Guest

    Post

    truthfully i dont think i know the difference between ado and dao, i might but i cant recall of the top of my head. either way this looks great thanks alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width