Solved

Add field to Jet 4.0 Database

Posted on 2002-03-14
8
151 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 50

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 50

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 

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 50

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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 76
VBA error replacing data 6 40
String manipulation in Visual Basic 7 62
Need Nag Screen for Reboot if system up time is over 14 days 12 50
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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