Solved

Add field to Jet 4.0 Database

Posted on 2002-03-14
8
150 Views
Last Modified: 2011-09-20
How do I add a new field to MSAccess 2000 database using ADO?

I have tried using rs.Fields.Append but I can't find a compatible data type.

I need to create a text field of 50 characters and allow zero length strings.

Thanks,

Lisp
0
Comment
Question by:Lisp
  • 4
  • 3
8 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 6866650
Hi Lisp,

Here is an example:

Private Sub Command5_Click()
    Dim oCat As ADOX.Catalog
    Dim oTable As ADOX.Table
    Dim sTable As String
   
    Set oCat = New ADOX.Catalog
    Text1.Text = "D:\Project\Icon\Database\database.mdb"
    oCat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & Text1.Text & ";"
       
       
    For Each oTable In oCat.Tables
        If oTable.Name = "POrder" Then
            oTable.Columns.Append "MyNewTextField", adWChar, 200
            oTable.Columns.Append "MyNewCurField", adCurrency
            oTable.Columns.Append "MyNewDateField", adDate
            oTable.Columns.Append "MyNewBolField", adBoolean
            oTable.Columns.Append "MyNewSmallIntField", adSmallInt
            Exit For
        End If
    Next
   
    Set oTable = Nothing
    Set oCat = Nothing
End Sub

Hope this help
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6866694
Use the oTable.Columns(item).Properties to set the Allow Zero Length Property..
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6866730
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column

Set cat = New ADOX.Catalog
With cat
    .ActiveConnection = "Your Jet connection goes here"
    Set tbl = .Tables("Table1")
    With tbl
        Set col = New ADOX.Column
        With col
            'This is probably the line you missed (I did!)
            'Unless you set the properties are not available when the column is created.
            .ParentCatalog = cat
            .Name = "ColumnName"
            .Type = adVarWChar
            .DefinedSize = 50
            .Properties("Jet OLEDB:Allow Zero Length").Value = True
        End With
        .Columns.Append col
    End With
End With
Set cat = Nothing

Anthony
0
 

Author Comment

by:Lisp
ID: 6866736
My system doesn't know what an ADOX is.  I'm guessing it is not the same thing as ADO.  Is there a different reference that I need?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Lisp
ID: 6866750
The reference I have loaded is "Active X Data Objects 2.6"
0
 

Author Comment

by:Lisp
ID: 6866764
I don't have any of these objects.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6866770
Use M$ ADO Ext 2.5 for Dll and Security
0
 

Author Comment

by:Lisp
ID: 6866840
Thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 51
Cannot enter table caption text in Word protected document 6 112
Prevent checkbox click event occur while editing it in vb6 8 34
TT Auto Dashboard 13 85
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now