Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Creating or changing tables in an access database

Creating or changing tables in an access database

Scheduled Pinned Locked Moved Visual Basic
databasedata-structuresquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    No e
    wrote on last edited by
    #1

    Continuing to slug through a VB6 to VS2008 conversion. In VB6 I was able to modify Access databases and add tables using a bit of code similar to the following (simplified for explanation)

    MyTableDef = MyDb.CreateTableDef(tblName)
    ' record type
    For i = 1 To UBound(Fields)
    MyField = MyTableDef.CreateField(Fields(i), FieldType(i), Size(i))
    MyTableDef.Fields.Append(MyField)
    Next
    MyDb.TableDefs.Append(MyTableDef)
    MyDb.Close()
    Exit Sub
    </pre>

    Fields, FieldType and Size are arrays with a name, length and type of field to be created and appended.

    I would like to duplicate this type of functionality using AD0 in VS2008. I know I can do it with a direct SQL command, but those could get real long and ugly. With this method I just add fields to an array and send them to this function.

    Any suggestions?

    Thanks in advance

    C 1 Reply Last reply
    0
    • N No e

      Continuing to slug through a VB6 to VS2008 conversion. In VB6 I was able to modify Access databases and add tables using a bit of code similar to the following (simplified for explanation)

      MyTableDef = MyDb.CreateTableDef(tblName)
      ' record type
      For i = 1 To UBound(Fields)
      MyField = MyTableDef.CreateField(Fields(i), FieldType(i), Size(i))
      MyTableDef.Fields.Append(MyField)
      Next
      MyDb.TableDefs.Append(MyTableDef)
      MyDb.Close()
      Exit Sub
      </pre>

      Fields, FieldType and Size are arrays with a name, length and type of field to be created and appended.

      I would like to duplicate this type of functionality using AD0 in VS2008. I know I can do it with a direct SQL command, but those could get real long and ugly. With this method I just add fields to an array and send them to this function.

      Any suggestions?

      Thanks in advance

      C Offline
      C Offline
      ChandraRam
      wrote on last edited by
      #2

      If you absolutely must use the same functionality, add a reference to DAO. The TableDef and Fields objects are defined there.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups