ADOX add bool field

M

Miro

Something weird I have run into when trying to add a boolean field to an
Access table by code.
-Just wondering if anyone else has run into this. ( vb.net 2005 express )

If I add any other field other than boolean the "command" version of adding
a field works great.
But if I try to add a boolean field, I get an exception error when its
trying to be added, so instead I have to use the function meathod.
-Code is below.

so basically I have to use Columns.Append( blablalblba
instead of the other way.

-All works...but just seemed to be a funny solution and I did tried it by
fluke and waisted a lot of my time trying to figure out why I couldnt add a
logical field.

So at least it will same some other person still trying to use adox. :)

Cheers

Miro








? TableFields(17)
{Simply_Teaching.FileLayout}
Prop_DBName: "MyDBName"
Prop_FieldLength: 1
Prop_FieldName: "BoolTest"
Prop_FieldType: "Logical"
Prop_TableName: "TableName"
Prop_VersionNo: "1.00"
Prop_KeyIndexField: False

======================
Dim NewAddingColumn As New ADOX.Column()

If TableFields(intFileSetup).Prop_FieldType =
"Logical" Then
ADOXTable(TableintFileSetup).Columns.Append( _
TableFields(intFileSetup).Prop_FieldName, _
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType),
_
TableFields(intFileSetup).Prop_FieldLength)

Else
NewAddingColumn.Name =
TableFields(intFileSetup).Prop_FieldName
NewAddingColumn.Type =
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType)

If TableFields(intFileSetup).Prop_FieldType <>
"Date" And _
TableFields(intFileSetup).Prop_FieldType <>
"Memo" Then

NewAddingColumn.DefinedSize =
TableFields(intFileSetup).Prop_FieldLength
End If

If TableFields(intFileSetup).Prop_KeyIndexField
= False Then
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColNullable
Else
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColFixed
End If

'Append the Column to the table.
ADOXTable(TableintFileSetup).Columns.Append(NewAddingColumn)
End If

=======================

Private Function ReturnFieldType(ByVal FieldType As String) As
ADOX.DataTypeEnum
Dim DataType As ADOX.DataTypeEnum

If FieldType = "String" Then
DataType = ADOX.DataTypeEnum.adVarWChar
ElseIf FieldType = "Date" Then
'DataType = ADOX.DataTypeEnum.adDBDate 'Throws out an error
DataType = ADOX.DataTypeEnum.adDate
ElseIf FieldType = "Logical" Or FieldType = "Boolean" Then
'datatype = adox.DataTypeEnum.
DataType = ADOX.DataTypeEnum.adBoolean
ElseIf FieldType = "Memo" Then
DataType = ADOX.DataTypeEnum.adLongVarWChar
End If

Return DataType
End Function
 
P

Paul Clement

¤ Something weird I have run into when trying to add a boolean field to an
¤ Access table by code.
¤ -Just wondering if anyone else has run into this. ( vb.net 2005 express )
¤
¤ If I add any other field other than boolean the "command" version of adding
¤ a field works great.
¤ But if I try to add a boolean field, I get an exception error when its
¤ trying to be added, so instead I have to use the function meathod.
¤ -Code is below.
¤
¤ so basically I have to use Columns.Append( blablalblba
¤ instead of the other way.
¤
¤ -All works...but just seemed to be a funny solution and I did tried it by
¤ fluke and waisted a lot of my time trying to figure out why I couldnt add a
¤ logical field.
¤
¤ So at least it will same some other person still trying to use adox. :)

You could probably avoid some of these issues by using Jet SQL.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acintsql.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
 
M

Miro

Thanks,

I saved the link but I am currently in the process of "learning" vb.net
So the adox for now has served its purpose. Now im onto forms and objects
and then
after, the "binded" ( i think thats what you call it ) objects on forms.
Creating a dummy app is the place to make these mystakes. :)
If I were to do it again, I think I will try to go the Jet SQL way.

Thanks again,

Miro
 
A

aaron.kempf

JetSQL?

****ing dipshits dont use jet for anything.. telling newbies to run
out and learn 2 different dialects of SQL is the most ridiculous thing
i've ever heard.

Dont use MDB for anything
Spit on anyone that still uses it.

-Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top