Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADOX adding columns

Posted on 2000-02-18
7
Medium Priority
?
843 Views
Last Modified: 2013-12-25
I'm very new to ADOX and I'm having some trouble.

I can't work out how to add new columns to a table with certain properties.

Just in case it matters, I'm creating a new Access 97 database.

The only thing I've managed to get to work is something like this:
'FieldX
Set objNewColumn = New ADOX.Column
objNewColumn.Name = "FieldX"
objNewColumn.DefinedSize = 15
objNewColumn.Attributes = adColNullable 'also objNewColumn.Attributes =
adColFixed
objNewTable.Columns.Append objNewColumn

1 - When Attributes = adColFixed, it won't allow me to leave the field
blank. If adColNullable, it allows NULL values. I would like to be able to
leave the field blank *without* allowing NULL values. How?

2 - I can't seem to be able to use the Type property. Any time I use it it
throws errors.... How can I make a column numeric this way?

Thanks

Pino
0
Comment
Question by:caraf_g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 2535377
Caraf_g, here is an example of creating an access database using ADOX

    Dim catAccess As New ADOX.Catalog
    Dim tblValExp As New ADOX.Table
    Dim cnnAccess As New ADODB.Connection
    Dim rstValExp As New ADODB.Recordset
    catAccess.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb"
    catAccess.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb"
    With tblValExp
        .Name = "tblValExp1"
        .Columns.Append "Stock Name", adVarWChar, 40
        .Columns.Append "Stock Symbol", adVarWChar, 6     '1
        .Columns.Append "Stock Price", adSingle       '2
        .Columns.Append "Est Date", adVarWChar, 10           '3
        .Columns.Append "Est Year", adVarWChar, 6         '4
        .Columns.Append "Price High(0)", adSingle     '5
        .Columns.Append "Price High(1)", adSingle     '6
        .Columns.Append "Price High(2)", adSingle     '7
        .Columns.Append "Price High(3)", adSingle     '8
        .Columns.Append "Price High(4)", adSingle     '9
        .Columns.Append "Price High(5)", adSingle     '10
    End With
    catAccess.Tables.Append tblValExp
    Set tblValExp = Nothing
    Set catAccess = Nothing
    cnnAccess.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb;Persist Security Info=False"
    rstValExp.Open "SELECT * FROM tblValExp1", cnnAccess, adOpenKeyset, adLockOptimistic
    rstValExp.AddNew
    rstValExp.Fields(0).Value = "Name"
    rstValExp.Fields(1).Value = "Symbol"
    rstValExp.Fields(2).Value = 1.5
    rstValExp.Fields(3).Value = Format(Now(), "dd/mm/yyyy")
    rstValExp.Fields(4).Value = "2000"
    rstValExp.Fields(5).Value = 1.5
    rstValExp.Fields(6).Value = 1.5
    rstValExp.Fields(7).Value = 1.5
    rstValExp.Fields(8).Value = 1.5
    rstValExp.Fields(9).Value = 1.5
    rstValExp.Fields(10).Value = 1.5
    rstValExp.Update
    rstValExp.MoveFirst
    Set rstValExp = Nothing
    Set cnnAccess = Nothing


0
 
LVL 10

Author Comment

by:caraf_g
ID: 2535518
The problem is not how to create a table with ADOX. I can do that.

The problem is how exactly can I define a column, so that it will allow the user to leave the contents blank, but without leaving the value NULL.

In other words, if nothing is entered, I want the column to have the value "", *not* NULL.

My guess is that I can do this through the Properties property of the ADOX.Column object. But HOW?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 2535607
I played about with the previous code and with the following settings, the field is fixed width 5 characters, empty strings are allowed but a NULL value is not allowed. Does this meet your needs?

Dim clmNew As New ADOX.Column
clmNew.Name = "Hello"
clmNew.Attributes = adColFixed And Not adColNullable
clmNew.Type = adVarWChar
clmNew.DefinedSize = 5
..Columns.Append clmNew
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Author Comment

by:caraf_g
ID: 2535733
Woohoo!

This DOES work:

'Additional Information
Set objNewColumn = New ADOX.Column
objNewColumn.Name = "Additional Information"
objNewColumn.Attributes = adColFixed And Not adColNullable
objNewColumn.Type = adVarWChar
objNewColumn.DefinedSize = 30
objNewTable.Columns.Append objNewColumn
objNewColumn.Properties("Jet OLEDB:Allow Zero Length").Value = True
objNewColumn.Properties("Default").Value = """"""


Don't ask. Just DON'T ASK.

<giggling maniacally>
0
 
LVL 10

Author Comment

by:caraf_g
ID: 2535736
Anyway - thanks for the effort. I'll give you an "A" for your trouble.
0
 
LVL 10

Author Comment

by:caraf_g
ID: 2535745
Don't you just love the """""" for the default value.

You'd think that "" would do. Wouldn't you? WOULDN'T YOU? But NO. That'd be WAY too intuitive. We can't have that, now, can we!

Ha!
0
 
LVL 10

Author Comment

by:caraf_g
ID: 2535748
End of rant
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

730 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