none
DAO Tabldef to ADO in Visual Basic 6 RRS feed

  • Question

  • I'm in the process of migrating our database from Access 97 to Access 2010 and We're using the VB6 application. I need help in converting the DAO Tabledef object to ADO so that the VB6 application can access the new db (.accdb)

    Sub CreateTableDefX()
    
       Dim dbsNorthwind As Database
       Dim tdfNew As TableDef
       Dim prpLoop As Property
    
       Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    
       ' Create a new TableDef object'
       Set tdfNew = dbsNorthwind.CreateTableDef("Contacts")
    
       With tdfNew
          ' Create fields and append them to the new TableDef' 
          ' object. This must be done before appending the' 
          ' TableDef object to the TableDefs collection of the' 
          ' Northwind database.'
          .Fields.Append .CreateField("FirstName", dbText)
          .Fields.Append .CreateField("LastName", dbText)
          .Fields.Append .CreateField("Phone", dbText)
          .Fields.Append .CreateField("Notes", dbMemo)
    
          Debug.Print "Properties of new TableDef object " & _
             "before appending to collection:"
    
          ' Enumerate Properties collection of new TableDef '
          ' object.'
          For Each prpLoop In .Properties
             On Error Resume Next
             If prpLoop <> "" Then Debug.Print "  " & _
               prpLoop.Name & " = " & prpLoop
             On Error GoTo 0
          Next prpLoop
    
          ' Append the new TableDef object to the Northwind '
          ' database.'
          dbsNorthwind.TableDefs.Append tdfNew
    
          Debug.Print "Properties of new TableDef object " & _
             "after appending to collection:"
    
          ' Enumerate Properties collection of new TableDef '
          ' object.'
          For Each prpLoop In .Properties
             On Error Resume Next
             If prpLoop <> "" Then Debug.Print "  " & _
               prpLoop.Name & " = " & prpLoop
             On Error GoTo 0
          Next prpLoop
    
       End With
    
       ' Delete new TableDef object since this is a '
       ' demonstration.'
       dbsNorthwind.TableDefs.Delete "Contacts"
    
       dbsNorthwind.Close
    
    End Sub
    Wednesday, August 9, 2017 7:05 PM

Answers

  • The TableDef in ADO (or ADOX actually) is a Table. See if the below link helps:

    http://www.mahipalreddy.com/vb/article86695.htm

    Keep in mind that for some properties there is no direct counterpart (such as allowing for a zero length string or allowing a column to be nullable) so you will have to write code specifically for those DAO properties. I would post a follow up if you get stuck on a specific attribute or property.

    Just an FYI, DAO is not limited to Access and can be used by VB 6 as well.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Thursday, August 10, 2017 5:00 PM

All replies

  • Hi natarajanct,

    Thanks for visiting our forum.

    Then here we mainly discuss general questions about Office client. Since your query is about Visual Basic 6 issues involving Access, we'll move your thread to the following dedicated MSDN forum for Access:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=accessdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,
    Yuki Sun


    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Thursday, August 10, 2017 6:13 AM
  • The TableDef in ADO (or ADOX actually) is a Table. See if the below link helps:

    http://www.mahipalreddy.com/vb/article86695.htm

    Keep in mind that for some properties there is no direct counterpart (such as allowing for a zero length string or allowing a column to be nullable) so you will have to write code specifically for those DAO properties. I would post a follow up if you get stuck on a specific attribute or property.

    Just an FYI, DAO is not limited to Access and can be used by VB 6 as well.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Thursday, August 10, 2017 5:00 PM