Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2000-02-21
4
Medium Priority
?
752 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 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