CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2001
    Posts
    6

    Creating a new Access DB

    Can anyone tell me how to generate a brand new MS Access Database from within VB? Thanks...


  2. #2
    Join Date
    Jul 2000
    Location
    Slovenia
    Posts
    77

    Re: Creating a new Access DB

    Call this routine. (I copy it from the MSDN library, this is not my sample)


    Sub CreateDatabaseX()
    Dim wrkDefault as Workspace
    Dim dbsNew as DATABASE
    Dim prpLoop as property

    ' get default Workspace.
    set wrkDefault = DBEngine.Workspaces(0)

    ' Make sure there isn't already a file with the name of
    ' the new database.
    If Dir("NewDB.mdb") <> "" then Kill "NewDB.mdb"

    ' Create a new encrypted database with the specified
    ' collating order.
    set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
    dbLangGeneral, dbEncrypt)

    With dbsNew
    Debug.print "Properties of " & .Name
    ' Enumerate the Properties collection of the new
    ' Database object.
    for Each prpLoop In .Properties
    If prpLoop <> "" then Debug.print " " & _
    prpLoop.Name & " = " & prpLoop
    next prpLoop
    End With

    dbsNew.Close

    End Sub





  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Creating a new Access DB

    Create database using ADO

    Make sure you have a reference set to the ADOX object library then use the following code.

    Dim objCatalog as ADOX.Catalog

    Set objCatalog = New ADOX.Catalog
    objCatalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\mynewdb.mdb"




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: Creating a new Access DB


    Dim appAccess as Access.Application

    set appAccess = new Access.Application
    appAccess.NewCurrentDatabase "C:\WINDOWS\Desktop\MyDB.mdb"
    set appAccess = nothing


    You will need to add Reference to "Microsoft Access 9.0 Object Library" (ACCESS 2000)

    RF




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

Featured