Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 MS-Access returns wrong 'AllowZeroLength' value

I'm using VB6 with ADOX to check the properties of Access 97 table columns. For the text fields it's important to prove that the field allows zero length or not.

The problem: the returned value is inverted. If the field allows zero length the return is false, if the field doesn't the value is true.

If a field doesn't support this property it returns false, which is right.

Could someone explain why the return is inverted?

Private Sub ReadTableStructure()
    Dim Cat As ADOX.Catalog
    Dim Tbl As ADOX.Table
    Dim Col As ADOX.Column

    Set Cat = New ADOX.Catalog
    Set Cat.ActiveConnection = Conn

    For Each Tbl In Cat.Tables
        For Each Col In Tbl.Columns
            bAllowZeroLength = GetDBPropertyBool(Col.Properties, "Jet OLEDB:Allow Zero Length", True)
        Next Col
    Next Tbl
End Sub

The Function GetDBPropertyBool:

Private Function GetDBPropertyBool(Properties As ADOX.Properties, sName As String, bDefaultValue As Boolean) As Boolean
    Dim Prop As ADOX.Property

    Set Prop = Properties(sName)
    If Prop Is Nothing Then
        GetDBPropertyBool = bDefaultValue
    Else
        GetDBPropertyBool = Prop.Value
    End If
End Function

In Access this property is true, in the VB6 Object it's false.

In Access this property is true

EDIT: I just found out that when i'm opening the table in Access in edit mode and just saving, the values which are given in VB6 are right. I don't change anything, just open to edit and save. Does anyone had already this problem?

like image 791
Nik Bo Avatar asked Oct 29 '22 23:10

Nik Bo


1 Answers

Actually I don't found an answer, why I am getting these wrong values. To open and save every table is no solution for us and our customers.

I just found an workaround, by using DAO to read the property rightly.

Private Sub ReadTableStructure(DB As DAO.Database)
    Dim i As Integer, j As Integer
    Dim Fld As DAO.Field
    Dim tdfLoop As TableDef

    For i = 0 To DB.TableDefs.Count - 1
        Set tdfLoop = DB(i)   
        For j = 0 To tdfLoop.Fields.Count - 1
            bAllowZeroLength = tdfLoop.Fields(j).AllowZeroLength
        Next j
    Next i
End Sub

If someone got an answer, why ADO doesn't returns the right value, please let me know.

like image 76
Nik Bo Avatar answered Nov 15 '22 06:11

Nik Bo