home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / newattch.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  7.2 KB  |  249 lines

  1. VERSION 4.00
  2. Begin VB.Form frmNewAttach 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "New Attached Table"
  5.    ClientHeight    =   3465
  6.    ClientLeft      =   2355
  7.    ClientTop       =   1590
  8.    ClientWidth     =   4245
  9.    Height          =   3870
  10.    HelpContextID   =   2016135
  11.    Icon            =   "NEWATTCH.frx":0000
  12.    Left            =   2295
  13.    LinkTopic       =   "Form1"
  14.    LockControls    =   -1  'True
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   3465
  18.    ScaleWidth      =   4245
  19.    Top             =   1245
  20.    Width           =   4365
  21.    Begin VB.ComboBox cboConnect 
  22.       Height          =   300
  23.       ItemData        =   "NEWATTCH.frx":030A
  24.       Left            =   120
  25.       List            =   "NEWATTCH.frx":0338
  26.       TabIndex        =   2
  27.       Top             =   1560
  28.       Width           =   3975
  29.    End
  30.    Begin VB.TextBox txtDatabase 
  31.       Height          =   285
  32.       Left            =   120
  33.       TabIndex        =   1
  34.       Top             =   960
  35.       Width           =   3975
  36.    End
  37.    Begin VB.CheckBox txtExclusive 
  38.       Caption         =   "AttachExclusive"
  39.       Height          =   225
  40.       Left            =   2160
  41.       TabIndex        =   5
  42.       Top             =   2520
  43.       Width           =   1785
  44.    End
  45.    Begin VB.CheckBox chkSavePassword 
  46.       Caption         =   "AttachSavePWD"
  47.       Height          =   225
  48.       Left            =   120
  49.       TabIndex        =   4
  50.       Top             =   2520
  51.       Width           =   1740
  52.    End
  53.    Begin VB.CommandButton cmdCancel 
  54.       Cancel          =   -1  'True
  55.       Caption         =   "&Close"
  56.       Height          =   435
  57.       Left            =   2160
  58.       TabIndex        =   7
  59.       Top             =   2880
  60.       Width           =   1905
  61.    End
  62.    Begin VB.CommandButton cmdAttach 
  63.       Caption         =   "&Attach"
  64.       Default         =   -1  'True
  65.       Enabled         =   0   'False
  66.       Height          =   435
  67.       Left            =   120
  68.       TabIndex        =   6
  69.       Top             =   2880
  70.       Width           =   1905
  71.    End
  72.    Begin VB.ComboBox cboTableName 
  73.       Height          =   300
  74.       Left            =   120
  75.       TabIndex        =   3
  76.       Top             =   2160
  77.       Width           =   3975
  78.    End
  79.    Begin VB.TextBox txtAttachName 
  80.       Height          =   285
  81.       Left            =   120
  82.       TabIndex        =   0
  83.       Top             =   360
  84.       Width           =   3975
  85.    End
  86.    Begin VB.Label lblLabels 
  87.       AutoSize        =   -1  'True
  88.       Caption         =   "Database Name: "
  89.       Height          =   195
  90.       Index           =   3
  91.       Left            =   105
  92.       TabIndex        =   11
  93.       Top             =   720
  94.       Width           =   1245
  95.    End
  96.    Begin VB.Label lblLabels 
  97.       AutoSize        =   -1  'True
  98.       Caption         =   "Table to Attach: "
  99.       Height          =   195
  100.       Index           =   2
  101.       Left            =   120
  102.       TabIndex        =   10
  103.       Top             =   1920
  104.       Width           =   1185
  105.    End
  106.    Begin VB.Label lblLabels 
  107.       AutoSize        =   -1  'True
  108.       Caption         =   "Connect String: "
  109.       Height          =   195
  110.       Index           =   1
  111.       Left            =   105
  112.       TabIndex        =   9
  113.       Top             =   1320
  114.       Width           =   1140
  115.    End
  116.    Begin VB.Label lblLabels 
  117.       AutoSize        =   -1  'True
  118.       Caption         =   "Attachment Name: "
  119.       Height          =   195
  120.       Index           =   0
  121.       Left            =   120
  122.       TabIndex        =   8
  123.       Top             =   105
  124.       Width           =   1365
  125.    End
  126. Attribute VB_Name = "frmNewAttach"
  127. Attribute VB_Creatable = False
  128. Attribute VB_Exposed = False
  129. Option Explicit
  130. Private Sub cmdCancel_Click()
  131.   Unload Me
  132. End Sub
  133. Sub Form_Load()
  134.   CenterMe Me, gnMDIFORM
  135.   cboConnect.ListIndex = 0
  136. End Sub
  137. Private Sub txtAttachName_Change()
  138.   If Len(txtAttachName.Text) > 0 Then
  139.     cmdAttach.Enabled = True
  140.   Else
  141.     cmdAttach.Enabled = False
  142.   End If
  143.   If cboTableName.ListCount > 0 Then cboTableName.Clear
  144. End Sub
  145. Private Sub cboConnect_Change()
  146.   If Len(txtAttachName.Text) > 0 Then
  147.     cmdAttach.Enabled = True
  148.   Else
  149.     cmdAttach.Enabled = False
  150.   End If
  151.   If cboTableName.ListCount > 0 Then cboTableName.Clear
  152. End Sub
  153. Private Sub cboTableName_DropDown()
  154.   Dim db As Database
  155.   Dim i As Integer
  156.   Dim sDataType As String       'data type string
  157.   Dim tdf As TableDef
  158.   On Error GoTo DDErr
  159.   SetHourglass
  160.   If cboTableName.ListCount = 0 Then
  161.     'fill in the list
  162.     sDataType = GetConnectStr()
  163.     If cboConnect.ListIndex = 0 Then
  164.       'special case for Jet mdb tables
  165.       Set db = gwsMainWS.OpenDatabase(gsNULL_STR, 0, 0, sDataType)
  166.     Else
  167.       Set db = gwsMainWS.OpenDatabase(gsNULL_STR, 0, 0, sDataType & ";" & cboConnect.Text)
  168.     End If
  169.     For Each tdf In db.TableDefs
  170.       If (tdf.Attributes And dbSystemObject) = 0 Then
  171.         cboTableName.AddItem tdf.Name
  172.       End If
  173.     Next
  174.   End If
  175.   Screen.MousePointer = vbDefault
  176.   Exit Sub
  177. DDErr:
  178.   ShowError
  179.   Exit Sub
  180. End Sub
  181. Private Sub cmdAttach_Click()
  182.   On Error GoTo AttachErr
  183.   Dim sConnect As String
  184.   Dim tbl As TableDef
  185.   Dim i As Integer
  186.   If DupeTableName(txtAttachName.Text) = True Then
  187.     txtAttachName.SetFocus
  188.     Exit Sub
  189.   End If
  190.   MsgBar "Attaching " & txtAttachName.Text, True
  191.   SetHourglass
  192.   sConnect = GetConnectStr()
  193.   'set the properties
  194.   Set tbl = gdbCurrentDB.CreateTableDef(txtAttachName.Text)
  195.   tbl.SourceTableName = cboTableName.Text
  196.   tbl.Connect = sConnect
  197.   If chkSavePassword.Value = 1 Then
  198.     tbl.Attributes = dbAttachSavePWD
  199.   End If
  200.   If txtExclusive.Value = 1 Then
  201.     tbl.Attributes = tbl.Attributes Or dbAttachExclusive
  202.   End If
  203.   gdbCurrentDB.TableDefs.Append tbl
  204.   RefreshTables frmTables.lstTables, True
  205.   'make sure and remove it if it was overwritten
  206.   frmAttachments.grdTables.Col = 0
  207.   For i = 1 To frmAttachments.grdTables.Rows - 1
  208.     frmAttachments.grdTables.Row = i
  209.     If UCase(frmAttachments.grdTables.Text) = UCase(txtAttachName.Text) Then
  210.       frmAttachments.grdTables.RemoveItem i
  211.       Exit For
  212.     End If
  213.   Next
  214.   'add it to the list
  215.   frmAttachments.grdTables.AddItem txtAttachName.Text & Chr(9) & cboTableName.Text & Chr(9) & sConnect
  216.   'get rid of the 1st item if it is blank
  217.   frmAttachments.grdTables.Row = 0
  218.   frmAttachments.grdTables.Col = 0
  219.   If Len(frmAttachments.grdTables.Text) = 0 Then
  220.     frmAttachments.grdTables.RemoveItem 0
  221.   End If
  222.   Screen.MousePointer = vbDefault
  223.   txtAttachName.Text = gsNULL_STR
  224.   cboTableName.Text = gsNULL_STR
  225.   MsgBar gsNULL_STR, False
  226.   Screen.MousePointer = vbDefault
  227.   Exit Sub
  228. AttachErr:
  229.   ShowError
  230.   Exit Sub
  231. End Sub
  232. Private Function GetConnectStr() As String
  233.   On Error GoTo GCErr
  234.   Dim sTmp As String
  235.   If cboConnect.ListIndex = 0 Then
  236.     sTmp = ";"
  237.   Else
  238.     sTmp = cboConnect.Text & ";"
  239.   End If
  240.   If Len(txtDatabase.Text) > 0 Then
  241.     sTmp = sTmp & "database=" & txtDatabase
  242.   End If
  243.   GetConnectStr = sTmp
  244.   Exit Function
  245. GCErr:
  246.   ShowError
  247.   Exit Function
  248. End Function
  249.