home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / VISDATA / ATTACH.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-26  |  5.8 KB  |  197 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAttachments 
  3.    Caption         =   "
  4.    ClientHeight    =   2895
  5.    ClientLeft      =   3870
  6.    ClientTop       =   2595
  7.    ClientWidth     =   6075
  8.    HelpContextID   =   2016086
  9.    Icon            =   "ATTACH.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   2895
  14.    ScaleWidth      =   6075
  15.    ShowInTaskbar   =   0   'False
  16.    Begin VB.ListBox lstTables 
  17.       Height          =   2400
  18.       Left            =   30
  19.       MultiSelect     =   1  'Simple
  20.       Sorted          =   -1  'True
  21.       TabIndex        =   4
  22.       Top             =   15
  23.       Width           =   6000
  24.    End
  25.    Begin VB.PictureBox picButtons 
  26.       Align           =   2  'Align Bottom
  27.       Appearance      =   0  'Flat
  28.       BorderStyle     =   0  'None
  29.       ForeColor       =   &H80000008&
  30.       Height          =   405
  31.       Left            =   0
  32.       ScaleHeight     =   405
  33.       ScaleWidth      =   6075
  34.       TabIndex        =   0
  35.       Top             =   2484
  36.       Width           =   6075
  37.       Begin VB.CommandButton cmdNew 
  38.          Caption         =   "
  39. (&N)"
  40.          Height          =   330
  41.          Left            =   120
  42.          MaskColor       =   &H00000000&
  43.          TabIndex        =   3
  44.          Top             =   45
  45.          Width           =   1815
  46.       End
  47.       Begin VB.CommandButton cmdReAttach 
  48.          Caption         =   "
  49. (&R)"
  50.          Height          =   330
  51.          Left            =   2160
  52.          MaskColor       =   &H00000000&
  53.          TabIndex        =   2
  54.          Top             =   45
  55.          Width           =   1845
  56.       End
  57.       Begin VB.CommandButton cmdClose 
  58.          Cancel          =   -1  'True
  59.          Caption         =   "
  60. (&C)"
  61.          Height          =   330
  62.          Left            =   4200
  63.          MaskColor       =   &H00000000&
  64.          TabIndex        =   1
  65.          Top             =   45
  66.          Width           =   1845
  67.       End
  68.    End
  69. Attribute VB_Name = "frmAttachments"
  70. Attribute VB_GlobalNameSpace = False
  71. Attribute VB_Creatable = False
  72. Attribute VB_PredeclaredId = True
  73. Attribute VB_Exposed = False
  74. Option Explicit
  75. '>>>>>>>>>>>>>>>>>>>>>>>>
  76. Const FORMCAPTION = "
  77. Const BUTTON1 = "
  78. (&N)"
  79. Const BUTTON2 = "
  80. (&R)"
  81. Const BUTTON3 = "
  82. (&C)"
  83. '>>>>>>>>>>>>>>>>>>>>>>>>
  84. Sub cmdClose_Click()
  85.   Unload Me
  86. End Sub
  87. Sub cmdNew_Click()
  88.   frmNewAttach.Show vbModal
  89. End Sub
  90. Sub cmdReAttach_Click()
  91.   On Error GoTo REAErr
  92.   Dim i As Integer
  93.   Dim sTmp As String
  94.   Screen.MousePointer = vbHourglass
  95.  refreshlink 
  96.   For i = 0 To lstTables.ListCount - 1
  97.     If lstTables.Selected(i) Then
  98.       sTmp = Trim$(Left$(lstTables.Text, InStr(lstTables.Text, vbTab)))
  99.       gdbCurrentDB.TableDefs(sTmp).RefreshLink
  100.     End If
  101.   Next
  102.   MsgBar vbNullString, False
  103.   Screen.MousePointer = vbDefault
  104.   Exit Sub
  105. REAErr:
  106.   ShowError
  107.   If i > 0 Then
  108.     Resume Next    '
  109.   End If
  110. End Sub
  111. Sub Form_Load()
  112.   On Error GoTo FLErr
  113.   Dim tdf As TableDef
  114.   Dim i As Integer
  115.   Me.Caption = FORMCAPTION
  116.   cmdNew.Caption = BUTTON1
  117.   cmdReAttach.Caption = BUTTON2
  118.   cmdClose.Caption = BUTTON3
  119.  tabledefs 
  120.   For Each tdf In gdbCurrentDB.TableDefs
  121.     If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Or _
  122.        (tdf.Attributes And dbAttachedODBC) = dbAttachedODBC Then
  123.       lstTables.AddItem tdf.Name & String(32 - Len(tdf.Name), " ") & vbTab & tdf.SourceTableName & "=>" & tdf.Connect
  124.     End If
  125.   Next
  126.   Me.Height = 3360
  127.   Me.Width = 6195
  128.   Me.Top = 1000
  129.   Me.Left = 1000
  130.   Screen.MousePointer = vbDefault
  131.   Exit Sub
  132. FLErr:
  133.   ShowError
  134.   Unload Me
  135. End Sub
  136. Private Sub lstTables_DblClick()
  137.   On Error GoTo GTDErr
  138.   Screen.MousePointer = vbHourglass
  139.   gdbCurrentDB.TableDefs(Trim$(Left$(lstTables.Text, InStr(lstTables.Text, vbTab)))).RefreshLink
  140.   Screen.MousePointer = vbDefault
  141.   Exit Sub
  142. GTDErr:
  143.   ShowError
  144. End Sub
  145. Private Sub Form_Resize()
  146.   On Error Resume Next
  147.   If Me.WindowState = 1 Then Exit Sub
  148.   lstTables.Width = Me.ScaleWidth - (lstTables.Left * 2)
  149.   lstTables.Height = Me.ScaleHeight - (picButtons.Height + 40)
  150. End Sub
  151. Public Sub AddAttachment()
  152.   On Error GoTo AttachErr
  153.   Dim sConnect As String
  154.   Dim tbl As TableDef
  155.   Dim i As Integer
  156.   Dim sTmp As String
  157.   With frmNewAttach
  158.     If DupeTableName(.txtAttachName.Text) Then
  159.       .txtAttachName.SetFocus
  160.       Exit Sub
  161.     End If
  162.     MsgBar "
  163.  " & .txtAttachName.Text, True
  164.     Screen.MousePointer = vbHourglass
  165.     sConnect = .GetConnectStr()
  166.     '
  167.     Set tbl = gdbCurrentDB.CreateTableDef(.txtAttachName.Text)
  168.     tbl.SourceTableName = .cboTableName.Text
  169.     tbl.Connect = sConnect
  170.     If .chkSavePassword.Value = vbChecked Then
  171.       tbl.Attributes = dbAttachSavePWD
  172.     End If
  173.     If .chkExclusive.Value = vbChecked Then
  174.       tbl.Attributes = tbl.Attributes Or dbAttachExclusive
  175.     End If
  176.     gdbCurrentDB.TableDefs.Append tbl
  177.     '
  178.     For i = 0 To lstTables.ListCount - 1
  179.       sTmp = Trim$(Left$(lstTables.List(i), InStr(lstTables.List(i), vbTab)))
  180.       If UCase(sTmp) = UCase(.txtAttachName.Text) Then
  181.         lstTables.RemoveItem i
  182.         Exit For
  183.       End If
  184.     Next
  185.     '
  186.     lstTables.AddItem .txtAttachName.Text & String(32 - Len(.txtAttachName.Text), " ") & vbTab & .cboTableName.Text & "=>" & sConnect
  187.     Screen.MousePointer = vbDefault
  188.     .txtAttachName.Text = vbNullString
  189.     .cboTableName.Text = vbNullString
  190.   End With
  191.   MsgBar vbNullString, False
  192.   Screen.MousePointer = vbDefault
  193.   Exit Sub
  194. AttachErr:
  195.   ShowError
  196. End Sub
  197.