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. Database & SysAdmin
  3. Database
  4. Having trouble with a TableDef object...

Having trouble with a TableDef object...

Scheduled Pinned Locked Moved Database
questiondatabasebusinesshelpcareer
1 Posts 1 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
    new_phoenix
    wrote on last edited by
    #1

    I would like to be able to add a field to an existing table in Microsoft Access. It is my understanding that I would need to use a TableDef object. Could you give me some insights? The code I have now is like so:

    Option Compare Database

    Public dbsHeadcount As Database
    Public Cnxn As ADODB.Connection
    Public rstHyperionMany As ADODB.Recordset

    Function ProcessHeadcountFile()
    On Error GoTo ErrorHandler

    Dim strConn As String
    Dim rstLoadFile As ADODB.Recordset
    Dim cmdSQLLoadFile As ADODB.Command
    Dim strSQLLoadFile As String
    Dim rstHyperionOne As ADODB.Recordset
    Dim cmdSQLHyperionOne As ADODB.Command
    Dim strSQLHyperionOne As String
    Dim cmdSQLHyperionMany As ADODB.Command
    Dim strSQLHyperionMany As String
    Dim strFileName As String
    Dim qdfTemp As QueryDef
    Dim qdfNew As QueryDef
    Dim strHoldRecString As String
    Dim strMessage As String
    
    Set dbsHeadcount = OpenDatabase("J:\\\\Headcount Database.mdb")
    Set Cnxn = New ADODB.Connection
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & \_
        "Data Source=J:\\\\Headcount Database.mdb;"
    Cnxn.Open strConn
    
    Call LoadExcelIntoAccessTable
    Set cmdSQLInputFile = New ADODB.Command
    Set cmdSQLInputFile.ActiveConnection = Cnxn
    Set cmdSQLHyperionMany = New ADODB.Command
    Set cmdSQLHyperionMany.ActiveConnection = Cnxn
    strSQLHyperionMany = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_
        "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_
        "FROM \[tblInputFile\]"
    cmdSQLHyperionMany.CommandType = adCmdText
    cmdSQLHyperionMany.CommandText = strSQLHyperionMany
    Set rstHyperionMany = cmdSQLHyperionMany.Execute()
    rstHyperionMany.MoveFirst
    Call CreateIndexesForLoadedTable
    

    ErrorHandler:
    If Err <> 0 Then
    MsgBox Err.Source & ":" & Err.Description, , "Error and Error #" & Err.Number
    End If
    End Function

    Sub LoadExcelIntoAccessTable()
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    "tblInputFile", "C:/Employees.xls", True
    End Sub

    Sub CreateIndexesForLoadedTable()
    Dim tdfInputFile As TableDef
    Set tdfInputFile = dbsHeadcount.CreateTableDef("tblInputFile")
    tdfInputFile.Fields.Append tdfInputFile.CreateField("Date", dbDate)
    dbsHeadcount.TableDefs.Append tdfInputFile

    ERROR: Here is where it is saying that tblInputFile already exists. How do I append the field called "Date" to the existing table called tblInpu
    
    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