Results 1 to 4 of 4

Thread: Mdb

  1. #1

    Thread Starter
    Junior Member Cipher's Avatar
    Join Date
    Dec 2004
    Location
    In your closet!
    Posts
    23

    Mdb

    How to I create a recordset or DB that I can load through VB?
    "It is a hard thing to fall, it is even harder to admit to that fall."

    -Darth Treya

    Star Wars: Knights of the Old Republic II

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Mdb

    Quote Originally Posted by Cipher
    How to I create a recordset or DB that I can load through VB?
    .

    You will have to be a bit more descriptive than that.

  3. #3

    Thread Starter
    Junior Member Cipher's Avatar
    Join Date
    Dec 2004
    Location
    In your closet!
    Posts
    23

    Re: Mdb

    Well you know the Biblio.mdb that comes with VB. How do I make my own mdb.

    Mdb= Microsoft Data Base.

    Because I want to load the field and tables through VB.

    EDIT: Maybe this belongs in DATabase
    "It is a hard thing to fall, it is even harder to admit to that fall."

    -Darth Treya

    Star Wars: Knights of the Old Republic II

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Mdb

    Here's a code snippet that demonstrates how to create an Access database and a table in the database. You'll need to add references to:
    Microsoft ActiveX Data Objects 2.x Library
    Microsoft ADO Ext. 2.x for DDL and Security
    VB Code:
    1. Public Sub MakeDB()
    2.  
    3.     Dim cat As ADOX.Catalog
    4.     Dim cn As ADODB.Connection
    5.    
    6.     Dim newDB As String
    7.     Dim DBVersion As Integer
    8.     '
    9.     '   Create a new Access database
    10.     '   Note: Valid 'Engine Type' 3 is Access2, 4 is Access97, 5 is Access2000
    11.     '
    12.     newDB = "c:\mynewdb.mdb"    ' Path & name of new database
    13.     DBVersion = 5               ' Create Access 2000 database
    14.    
    15.     Set cat = New ADOX.Catalog
    16.     cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & newDB & ";Jet OLEDB:Engine Type=" & DBVersion
    17.     Set cat = Nothing
    18.     '
    19.     '   Create a table in the database
    20.     '
    21.     Set cn = New ADODB.Connection
    22.     cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & newDB
    23.    
    24.     Dim sql As String
    25.     sql = "create table [mynewtable] ("
    26.     sql = sql & "[Surname] TEXT(30), "
    27.     sql = sql & "[First Names] TEXT(30), "
    28.     sql = sql & "[Business Name] TEXT(40), "
    29.     sql = sql & "[Phone] TEXT(16), "
    30.     sql = sql & "[Fax] TEXT(16), "
    31.     sql = sql & "[Birthdate] DATETIME, "
    32.     sql = sql & "[Number of Kids] SMALLINT, "
    33.     sql = sql & "[Notes] TEXT(250))"
    34.     cn.Execute sql
    35.     '
    36.     '   Create the indexes
    37.     '
    38.     sql = "create index [Surname] on [mynewtable] ([Surname])"
    39.     cn.Execute sql
    40.     sql = "create unique index [Business Name] on [mynewtable] ([Business Name])"
    41.     cn.Execute sql
    42.    
    43.     cn.Close
    44.     Set cn = Nothing
    45.    
    46. End Sub
    Hope that helps. BTW there are some really good tutorials to be found in the Database forum.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

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