home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 011A / DBW32V11.ZIP / DBCREATE.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-12-09  |  2.3 KB  |  83 lines

  1. Attribute VB_Name = "DBCreate"
  2. ' Database Creation Procedures
  3. ' ⌐1995,1996 Tuomas Salste (vbshop@netgate.net)
  4. ' Include this module in your project if needed
  5.  
  6. Option Explicit
  7. Public Const dbCounter = -10
  8. Public Const dbFixedText = -11
  9. Public Const idxUnique = True
  10. Public Const idxNonUnique = False
  11. Public Const idxPrimary = True
  12. Public Const idxNonPrimary = False
  13.  
  14.  
  15. ' Appends a new field 'FieldName' to a TableDef
  16. Sub AddField(td As TableDef, ByVal FieldName As String, ByVal FieldType As Integer, ByVal Size As Integer, Optional ByVal Required As Variant, Optional ByVal AllowZeroLength As Variant, Optional ByVal DefaultValue As Variant, Optional ByVal ValidationRule As Variant, Optional ByVal ValidationText As Variant)
  17.  
  18. Dim fl As New Field
  19. fl.Name = FieldName
  20. If FieldType = dbCounter Then
  21.     fl.Type = dbLong
  22.     fl.Attributes = fl.Attributes Or dbAutoIncrField
  23. ElseIf FieldType = dbFixedText Then
  24.     fl.Type = dbText
  25.     fl.Attributes = fl.Attributes Or dbFixedField
  26. Else
  27.     fl.Type = FieldType
  28. End If
  29.  
  30. ' AllowZeroLength
  31. ' Text and memo fields can allow zero length strings ("")
  32. If FieldType = dbText Or FieldType = dbMemo Or FieldType = dbFixedText Then
  33.     If Not IsMissing(AllowZeroLength) Then
  34.         fl.AllowZeroLength = CBool(AllowZeroLength)
  35.     End If
  36. End If
  37.  
  38. ' Required
  39. If Not IsMissing(Required) Then
  40.     fl.Required = CBool(Required)
  41. End If
  42.  
  43. ' DefaultValue
  44. If Not IsMissing(DefaultValue) Then
  45.     fl.DefaultValue = DefaultValue
  46. End If
  47.  
  48. ' Validation
  49. If Not IsMissing(ValidationRule) Then
  50.     fl.ValidationRule = ValidationRule
  51. End If
  52. If Not IsMissing(ValidationText) Then
  53.     fl.ValidationText = ValidationText
  54. End If
  55.  
  56. If FieldType = dbText Then fl.Size = Size
  57. td.Fields.Append fl
  58.  
  59. End Sub
  60.  
  61.  
  62. ' Appends a new index 'IndexName' to a TableDef
  63. Sub AddIndex(td As TableDef, ByVal IndexName As String, ByVal IndexFields As String, ByVal IndexPrimary As Integer, ByVal IndexUnique As Integer)
  64.  
  65. Dim idx As New Index
  66. idx.Name = IndexName
  67. idx.Fields = IndexFields
  68. idx.Primary = IndexPrimary
  69. idx.Unique = IndexUnique
  70. td.Indexes.Append idx
  71.  
  72. End Sub
  73.  
  74. ' Appends a QueryDef 'QueryName' to a database
  75. Sub AddQueryDef(db As Database, ByVal QueryName As String, ByVal SQL As String)
  76.  
  77. Dim qd As QueryDef
  78. On Error Resume Next
  79. Set qd = db.CreateQueryDef(QueryName, SQL)
  80.  
  81. End Sub
  82.  
  83.