Solved

Add field to Jet 4.0 Database

Posted on 2002-03-14
8
149 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

17 Experts available now in Live!

Get 1:1 Help Now