?
Solved

ADO / Access 97 / VB6 / "Allow Zero Length"

Posted on 2000-02-21
4
Medium Priority
?
739 Views
Last Modified: 2008-03-10

ADO Experts!

I need to create a table in an Access 97 .MDB, and append the fields I want.  That's easy enough.  But when I view the table's design in Access, I want the 'Allow Zero Length' property to be "YES", not "NO".  In short, these newly-created fields must allow zero-length values.

As you can see from the code snippet below, I'm trying to set the col's Attributes property to 'adColNullable', with no effect.  The 'Allow Zero Length' property in the resultant table is still 'No'.

These fields are text type fields, and they will not be part of the table's key.  Here is the current code I am using:


------------------------------START CODE
Dim n           As Long
Dim tbl         As ADOX.Table
Dim col         As ADOX.Column
Dim key1        As ADOX.Key
Dim cat         As ADOX.Catalog
 . . .
Set cat = New ADOX.Catalog
cat.ActiveConnection = "Provider=" & MSJ_OLEDB_40 & ";" & "Data Source=" & sDBPath
 . . .
Set tbl = New ADOX.Table
tbl.Name = "Test1"
'** Add columns to the new table
Call tbl.Columns.Append("ID", adDouble)
Call tbl.Columns.Append("Description", adVarWChar, 100)
Call tbl.Columns.Append("Suburb", adVarWChar, 50)
 . . . Add other columns . . .
For n = 1 To 20
   Call tbl.Columns.Append("Field_" & n, adVarWChar, 50)
Next

'** Set keys, attributes on all columns just added.
For Each col In tbl.Columns
   Select Case (UCase(col.Name))
   Case "ID", "DESCRIPTION"
      '** For these fields only, create a Primary Key
      Set key1 = tbl.Keys("MyKey")
      If (key1 Is Nothing) Then
         tbl.Keys.Append "MyKey", adKeyPrimary, col.Name
      Else
         tbl.Keys("MyKey").Columns.Append col.Name
      End If
   Case Else
      '** THESE FIELDS (say, 20 or 30) MUST ALLOW ZERO-LENGTH VALUES!
      '** This isn't working...
      col.Attributes = adColNullable
   End Select
Next
'** Add this new table to the Catalog.  Works fine.
cat.Tables.Append tbl
-----------------------------END CODE


How can I do this, using ADO v2.1, VB6, and Access 97?  The right answer can't be far off from what I've got here--by which I mean, I shouldn't have to turn back to DAO or something else for a solution.  ADO should be able to do this.

Thanks in advance for a helpful solution.

Breck Ryker
breck_ryker@mpsisys.com
0
Comment
Question by:bryker
[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
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 2543790
I found this code in another question that recently ask about it.

'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 = """""" 

The question is Q.10297409 (in VB - database).
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2544001
Emoreau's code should work. Despite this I still wanted to post this comment because there is a difference between a column that accepts empty strings and a column that accepts NULL values. VB clearly distinguishes an empty string ("") from a string that has no value (NULL). In other words: your code works perfectly, though you tell it to create a Nullable column, which is not the same as a column that accepts strings with zero length.
0
 

Author Comment

by:bryker
ID: 2544084

I had about given up on getting this to work, when I realized that my Table had not yet been appended to my Catalog object.  I had been frustrated by the fact that my Column object had NO properties available to be set.  After appending the table to the cat, properties were available--which only makes sense, now that I think about it.

Thanks for your help and research into the other similar question.
0
 

Author Comment

by:bryker
ID: 2544103

(Aside to p_biggelaar:)

I see how that looks now.  When I wrote:

>I'm trying to set the col's Attributes property to 'adColNullable', with no effect

I should have said something like "I'm finagling the only property I see available, and that's not helping me."  Yes, ADO duly made my field nullable, as you indicate, but I hadn't yet begun to address its 'zero-lengthability'.

Thanks for the input.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

770 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