home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / bp_6_93 / bonus / dmsrc / faddindx.txt < prev    next >
Text File  |  1995-02-26  |  4KB  |  144 lines

  1. Sub cAdd_Click (Index As Integer)
  2.     Dim PlMn As String
  3.  
  4.     PlMn = "+"
  5.     If Index = 1 Then PlMn = "-"
  6.  
  7.     cFields.AddItem PlMn & cFieldList.List(cFieldList.ListIndex)
  8.     cFieldList.RemoveItem cFieldList.ListIndex
  9.  
  10.     cFieldList.ListIndex = -1
  11.     For I = 0 To 1
  12.         cAdd(I).Enabled = False
  13.     Next I
  14.     If cFields.ListCount > 0 And cIndexName <> "" Then
  15.         cDone.Enabled = True
  16.         cDone.Default = True
  17.     End If
  18.     cFieldList.SetFocus
  19. End Sub
  20.  
  21. Sub cCancel_Click ()
  22. 'Close Dialog
  23. Unload fAddIndex
  24. End Sub
  25.  
  26. Sub cDone_Click ()
  27.     Dim idx As New Index
  28.     Dim tempFields As String
  29.     Dim temp As String
  30.     Dim I As Integer
  31.     Dim AddErr As Integer
  32.     
  33.     On Error Resume Next
  34.  
  35.     'Set up index properties
  36.     idx.Name = cIndexName
  37.     idx.Primary = -cPrimary
  38.     idx.Unique = -cUnique
  39.     tempFields = ""
  40.     For I = 0 To cFields.ListCount - 1
  41.         temp = cFields.List(I)
  42.         temp = Left$(temp, 1) & "[" & Right$(temp, Len(temp) - 1) & "]"
  43.         tempFields = tempFields + temp + ";"
  44.     Next I
  45.     If Len(tempFields) > 255 Then
  46.         MsgBox "Too many fields in Index.  Remove some and try again.", 64, "Data Manager"
  47.     Else
  48.         'Remove the last semicolon
  49.         idx.Fields = Left$(tempFields, Len(tempFields) - 1)
  50.         
  51.         'Append to the Index Collection
  52.         gDatabase.TableDefs(cTableName).Indexes.Append idx
  53.         AddErr = Err
  54.         If AddErr <> 0 Then
  55.             MsgBox "Error Adding Index: " + Chr$(13) + Error$, 64, "Data Manager"
  56.         End If
  57.     
  58.         If AddErr = 3283 Then 'Primary Key already exists
  59.             'cPrimary = 0
  60.         ElseIf AddErr = 3277 Then 'Too many fields in list
  61.             cFields.ListIndex = 0
  62.         Else
  63.             'Close Dialog
  64.             Unload fAddIndex
  65.         End If
  66.     End If
  67. End Sub
  68.  
  69. Sub cFieldList_Click ()
  70.     If cFieldList.ListIndex <> -1 Then
  71.         cAdd(0).Enabled = True
  72.         cAdd(1).Enabled = True
  73.         cRemove.Enabled = False
  74.         cFields.ListIndex = -1
  75.         cAdd(0).Default = True
  76.     End If
  77. End Sub
  78.  
  79. Sub cFieldList_DblClick ()
  80.     'Add the item
  81.     cAdd_Click (0)
  82. End Sub
  83.  
  84. Sub cFields_Click ()
  85.     If cFields.ListIndex <> -1 Then
  86.         cFieldList.ListIndex = -1
  87.         cRemove.Enabled = True
  88.         cAdd(0).Enabled = False
  89.         cAdd(1).Enabled = False
  90.     End If
  91. End Sub
  92.  
  93. Sub cFields_DblClick ()
  94.     'Remove the item
  95.     cRemove_Click
  96. End Sub
  97.  
  98. Sub cIndexName_Change ()
  99.     If cFields.ListCount > 0 And cIndexName <> "" Then
  100.         cDone.Enabled = True
  101.         cDone.Default = True
  102.     Else
  103.         cDone.Enabled = False
  104.     End If
  105. End Sub
  106.  
  107. Sub cRemove_Click ()
  108.     Dim temp As String
  109.     temp = cFields.List(cFields.ListIndex)
  110.     cFields.RemoveItem cFields.ListIndex
  111.  
  112.     cFieldList.AddItem Right$(temp, Len(temp) - 1)
  113.  
  114.     If cFields.ListCount <= 0 Then
  115.         cDone.Enabled = False
  116.     End If
  117.     cFieldList.ListIndex = 0
  118.     cFieldList.SetFocus
  119. End Sub
  120.  
  121. Sub Form_Activate ()
  122.     Dim I As Integer
  123.     Dim TD As Tabledef
  124.     Dim FieldCount As Integer
  125.  
  126.     On Error Resume Next
  127.  
  128.     Screen.MousePointer = 11
  129.     Set TD = gDatabase.TableDefs(cTableName.Caption)
  130.     FieldCount = TD.Fields.Count
  131.     If FieldCount > 0 Then 'it should be
  132.         For I = 0 To FieldCount - 1
  133.             If TD.Fields(I).Type <= 10 Then  'not ole or memo
  134.                 cFieldList.AddItem TD.Fields(I).Name
  135.             End If
  136.         Next I
  137.     End If
  138.     Screen.MousePointer = 0
  139.     'enable buttons
  140.     cDone.Enabled = False
  141.  
  142. End Sub
  143.  
  144.