Results 1 to 10 of 10

Thread: Create Database At Run-Time

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Wichita, KS, US
    Posts
    10

    Post

    Is there anyway to create and open databases at run-time?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Sure, here's an example of Creating an Access DB at runtime using the DAO Objects:
    Code:
    Private Sub Command1_Click()
        Dim oWork As Workspace
        Dim oDatabase As Database
        Dim oTable As TableDef
        Dim oField As Field
        
        Set oWork = Workspaces(0)
        'Create an Empty Database
        Set oDatabase = oWork.CreateDatabase("C:\NewDB.mdb", dbLangGeneral)
        'Create a Table Object
        Set oTable = oDatabase.CreateTableDef("Table1")
        'Create a Field Object
        Set oField = oTable.CreateField("Field1", dbText, 20)
        'Add the Field to the Table Object
        oTable.Fields.Append oField
        'Add the Table Object to the Database
        oDatabase.TableDefs.Append oTable
        'All Done, Close and Release the Objects
        oDatabase.Close
        oWork.Close
        Set oField = Nothing
        Set oTable = Nothing
        Set oDatabase = Nothing
        Set oWork = Nothing
        MsgBox "Database Created"
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Go to Project-->References and choose Microsoft DAO 3.5 Object Library or something like that. It should help

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Wichita, KS, US
    Posts
    10

    Post

    Thanks a lot, both of you!!! I don't know what I'd do without all you people that know what you're doing.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Wichita, KS, US
    Posts
    10

    Post

    Thanks for the reply, but I have run into another problem. I'm using VB 6 Learning Edition, and it doesn't seem to recognize Workspace, Database, TableDef, and Field as valid variable types. Is there anyway to get around this, or will I just need to upgrade.

  6. #6
    Addicted Member
    Join Date
    Jun 2006
    Posts
    219

    Re: Create Database At Run-Time

    In the above said method (post # 2) we must know how many fields we have....

    what i am asking is user only knows the fields.....is there is any way to make like that ?

    At a time can we make 2 tables in a mdb? (All rows to one table and columns to one table with its total value?)

    User will only see as per attached image....but in coding only we going to make tables in one mdb.....

    Please see and advice !!!
    Attached Images Attached Images  

  7. #7
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

  8. #8
    Addicted Member
    Join Date
    Jun 2006
    Posts
    219

    Re: Create Database At Run-Time

    Thanks for reply.

    Please advise, in this method can we convert Text1.text as field1 , text2.text as field2.....like that...?

  9. #9
    Addicted Member
    Join Date
    Jun 2006
    Posts
    219

    Re: Create Database At Run-Time

    Friends !

    I have 3 tables (structure and samples records attached). Now I want to create the final report as attached.

    Please guide me !!

    thanking you in anticipation.
    Attached Images Attached Images     

  10. #10
    Addicted Member
    Join Date
    Jun 2006
    Posts
    219

    Re: Create Database At Run-Time

    Please Help ME !!!

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