Ken
This is an example of Sams TYS Database programming with vb5. Hope this helps.
Niranjan
Option Explicit
Dim ws As Workspace
Dim db As Database
Dim td As TableDef
Dim fl As Field
Private Sub Command1_Click()
Dim strDBName As String
strDBName = "c:\MyDataBase.mdb"
On Error Resume Next
Set ws = DBEngine.Workspaces(0)
Set db = ws.CreateDatabase(strDBName, dbLangGeneral)
Set td = db.CreateTableDef("FieldTypes"
MakeField "BinaryField", dbBinary
MakeField "BooleanField", dbBoolean
MakeField "ByteField", dbByte
MakeField "CurrencyField", dbCurrency
MakeField "DateTimeField", dbDate
MakeField "DoubleField", dbDouble
MakeField "GUIDField", dbGUID
MakeField "IntegerField", dbInteger
MakeField "LongField", dbLong
MakeField "LongBinaryField", dbLongBinary
MakeField "MemoField", dbMemo
MakeField "SingleField", dbSingle
MakeField "TextField", dbText, 255
' invalid when creating JET databases
'MakeField "BigIntegerField", dbBigInt
'MakeField "CharField", dbChar, 5
'MakeField "DecimalField", dbDecimal
'MakeField "FloatField", dbFloat
'MakeField "NumericField", dbNumeric
'MakeField "TimeField", dbTime
'MakeField "TimeStampField", dbTimeStamp
'MakeField "VarBinaryField", dbVarBinary
'
' some special attributes
MakeField "AutoIncrField", dbLong, lngAttributes:=dbAutoIncrField
MakeField "HyperLinkField", dbMemo, lngAttributes:=dbHyperlinkField
'
db.TableDefs.Append td
'
MsgBox "Fields Added"
'
End Sub
Public Sub MakeField(strFieldName As String, intFieldType As Integer, Optional intSize As Integer, Optional lngAttributes As Long)
'
Set fl = td.CreateField(strFieldName, intFieldType)
'
If IsMissing(intSize) = False Then
fl.Size = intSize
End If
'
If IsMissing(lngAttributes) = False Then
fl.Attributes = lngAttributes
End If
'
td.Fields.Append fl
'
End Sub
Private Sub Command2_Click()
'
Dim strMsg As String
'
For Each fl In td.Fields
strMsg = ""
strMsg = strMsg & "Name: " & fl.Name & vbCrLf
strMsg = strMsg & "Type: " & CStr(fl.Type) & vbCrLf
strMsg = strMsg & "Size: " & CStr(fl.Size) & vbCrLf
strMsg = strMsg & "Attrib: " & CStr(fl.Attributes) & vbCrLf
MsgBox strMsg
Next
'
End Sub