Results 1 to 2 of 2

Thread: creating tables in a access database using code

  1. #1
    Guest

    Question

    Hi all

    I know how can a user can create a database.My problem is how can i define(create) fields in that specific database (the tables has to be predefined) and how can I specify the location to my data controls as the database can be any where on the harddrive.
    Please help



  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Netherlands Antilles
    Posts
    66
    Sure thing.
    try this, just make sure you reference your project to MS DAO 3.51 Object library for access 97 file or MS DAO 3.6 Object library for Access 2000 file. and change the fields to what you want.

    Dim TblFile As TableDef
    Dim IdxFile As Index
    Dim FLD As Field
    Dim DbsNew As Database
    Public DBCallData As Database
    Public CallSeconds As String

    Public Sub DataFileFind()
    DataFile = App.Path & "\database.mdb"
    If Dir(DataFile) <> "" Then ' if file exist. do nothing. else. create database
    Else
    'create database file
    Set DbsNew = DBEngine.CreateDatabase(DataFile, dbLangGeneral) 'create data file
    Set TblFile = DbsNew.CreateTableDef("SetupCall") ' create recordsets
    With TblFile
    .Fields.Append .CreateField("SendingMuxAddress", dbText, 50) 'add field names
    .Fields.Append .CreateField("OriginMuxAddress", dbText, 50)
    .Fields.Append .CreateField("Originator", dbText, 50)
    .Fields.Append .CreateField("CallSerialNum", dbText, 50)
    .Fields.Append .CreateField("VoicePort", dbText, 10)
    .Fields.Append .CreateField("TransDestNum", dbText, 50)
    .Fields.Append .CreateField("SourcePort", dbText, 50)
    .Fields.Append .CreateField("DestNum", dbText, 50)
    DbsNew.TableDefs.Append TblFile
    End With

    'IF INDEX NEEDED. USE CODING
    'Set IdxFile = TblFile.CreateIndex("IdxFile") 'add index
    'Set FLD = IdxFile.CreateField("Name") 'connect index to field
    'With IdxFile
    ' .Primary = True
    ' .Unique = True
    ' .Required = True
    'End With
    'IdxFile.Fields.Append FLD
    'TblFile.Indexes.Append IdxFile
    DbsNew.Close
    End If
    End Sub


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