home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mquery / mjoin.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-02  |  7.5 KB  |  238 lines

  1. VERSION 2.00
  2. Begin Form fJoin 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Join Tables"
  6.    ClientHeight    =   3900
  7.    ClientLeft      =   2580
  8.    ClientTop       =   2250
  9.    ClientWidth     =   7620
  10.    ControlBox      =   0   'False
  11.    Height          =   4305
  12.    Left            =   2520
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3900
  17.    ScaleWidth      =   7620
  18.    Top             =   1905
  19.    Width           =   7740
  20.    Begin Frame Frame1 
  21.       BackColor       =   &H00C0C0C0&
  22.       Caption         =   "Select type of Join"
  23.       Height          =   2175
  24.       Left            =   120
  25.       TabIndex        =   8
  26.       Top             =   1560
  27.       Width           =   7335
  28.       Begin OptionButton rRightjoin 
  29.          BackColor       =   &H00C0C0C0&
  30.          Caption         =   "Option1"
  31.          Height          =   255
  32.          Left            =   120
  33.          TabIndex        =   14
  34.          Top             =   1440
  35.          Width           =   255
  36.       End
  37.       Begin OptionButton rleftjoin 
  38.          BackColor       =   &H00C0C0C0&
  39.          Caption         =   "Option1"
  40.          Height          =   255
  41.          Left            =   120
  42.          TabIndex        =   13
  43.          Top             =   840
  44.          Width           =   255
  45.       End
  46.       Begin OptionButton rEqijoin 
  47.          BackColor       =   &H00C0C0C0&
  48.          Caption         =   "Option1"
  49.          Height          =   255
  50.          Left            =   120
  51.          TabIndex        =   12
  52.          Top             =   360
  53.          Value           =   -1  'True
  54.          Width           =   255
  55.       End
  56.       Begin Label Label3 
  57.          BackColor       =   &H00C0C0C0&
  58.          Caption         =   "Right  Join Include all rows from the right table and only those rows in the left  table where joined fields are equal"
  59.          Height          =   495
  60.          Left            =   600
  61.          TabIndex        =   11
  62.          Top             =   1440
  63.          Width           =   6495
  64.       End
  65.       Begin Label Label2 
  66.          BackColor       =   &H00C0C0C0&
  67.          Caption         =   "Left Join Include all rows from  left table and only those rows in the right table where joined fields are equal"
  68.          Height          =   495
  69.          Left            =   600
  70.          TabIndex        =   10
  71.          Top             =   840
  72.          Width           =   6495
  73.       End
  74.       Begin Label Label1 
  75.          BackColor       =   &H00C0C0C0&
  76.          Caption         =   "Equi-Join Include all rows from both tables where joined fields are equal."
  77.          Height          =   375
  78.          Left            =   600
  79.          TabIndex        =   9
  80.          Top             =   360
  81.          Width           =   6495
  82.       End
  83.    End
  84.    Begin CommandButton ClearJoinsButton 
  85.       BackColor       =   &H00C0C0C0&
  86.       Caption         =   "C&lear All Joins"
  87.       Height          =   375
  88.       Left            =   5880
  89.       TabIndex        =   7
  90.       Top             =   720
  91.       Width           =   1575
  92.    End
  93.    Begin CommandButton CloseButton 
  94.       BackColor       =   &H00C0C0C0&
  95.       Cancel          =   -1  'True
  96.       Caption         =   "&Close"
  97.       Height          =   375
  98.       Left            =   5880
  99.       TabIndex        =   6
  100.       Top             =   1200
  101.       Width           =   1575
  102.    End
  103.    Begin ListBox cFieldList2 
  104.       BackColor       =   &H00FFFFFF&
  105.       Height          =   1200
  106.       Left            =   3960
  107.       TabIndex        =   4
  108.       Tag             =   "OL"
  109.       Top             =   240
  110.       Width           =   1815
  111.    End
  112.    Begin ListBox cFieldList1 
  113.       BackColor       =   &H00FFFFFF&
  114.       Height          =   1200
  115.       Left            =   2040
  116.       TabIndex        =   3
  117.       Tag             =   "OL"
  118.       Top             =   240
  119.       Width           =   1815
  120.    End
  121.    Begin CommandButton AddJoinButton 
  122.       BackColor       =   &H00C0C0C0&
  123.       Caption         =   "&Add Join to Query"
  124.       Enabled         =   0   'False
  125.       Height          =   375
  126.       Left            =   5880
  127.       TabIndex        =   1
  128.       Top             =   240
  129.       Width           =   1575
  130.    End
  131.    Begin ListBox cTableList 
  132.       BackColor       =   &H00FFFFFF&
  133.       Height          =   1200
  134.       Left            =   120
  135.       MultiSelect     =   1  'Simple
  136.       TabIndex        =   0
  137.       Tag             =   "OL"
  138.       Top             =   240
  139.       Width           =   1815
  140.    End
  141.    Begin Label FieldsLabel 
  142.       Alignment       =   2  'Center
  143.       BackColor       =   &H00C0C0C0&
  144.       Caption         =   "Select Fields to Join Selected Tables on:"
  145.       Height          =   192
  146.       Left            =   2040
  147.       TabIndex        =   5
  148.       Top             =   0
  149.       Width           =   3732
  150.    End
  151.    Begin Label TableListLabel 
  152.       BackColor       =   &H00C0C0C0&
  153.       Caption         =   "Select Table Pair:"
  154.       Height          =   192
  155.       Left            =   120
  156.       TabIndex        =   2
  157.       Top             =   0
  158.       Width           =   1812
  159.    End
  160. Option Explicit
  161. Dim FTbl1 As String
  162. Dim FTbl2 As String
  163. Sub AddJoinButton_Click ()
  164.   Dim i As Integer
  165.    ' check for type of join
  166.     Select Case reqijoin.Value ' equi join
  167.     Case True
  168.     fQuery.cJoinFields.AddItem FTbl1 + " INNER JOIN " + FTbl2 + " ON " + FTbl1 + "." + "[" + cFieldList1 + "]" + "=" + FTbl2 + "." + "[" + cFieldList2 + "]"
  169.     End Select
  170.     Select Case rleftjoin.Value ' left join
  171.     Case True
  172.     fQuery.cJoinFields.AddItem FTbl1 + " LEFT JOIN " + FTbl2 + " ON " + FTbl1 + "." + "[" + cFieldList1 + "]" + "=" + FTbl2 + "." + "[" + cFieldList2 + "]"
  173.     End Select
  174.     Select Case rRightjoin.Value ' right join
  175.     Case True
  176.     fQuery.cJoinFields.AddItem FTbl1 + " RIGHT JOIN " + FTbl2 + " ON " + FTbl1 + "." + "[" + cFieldList1 + "]" + "=" + FTbl2 + "." + "[" + cFieldList2 + "]"
  177.     End Select
  178.   For i = 0 To cTableList.ListCount - 1
  179.     cTableList.Selected(i) = False
  180.   Next
  181. End Sub
  182. Sub cFieldList1_Click ()
  183.   If cFieldList2 <> "" Then
  184.     AddJoinButton.Enabled = True
  185.   End If
  186. End Sub
  187. Sub cFieldList2_Click ()
  188.   If cFieldList1 <> "" Then
  189.     AddJoinButton.Enabled = True
  190.   End If
  191. End Sub
  192. Sub ClearJoinsButton_Click ()
  193.   fQuery.cJoinFields.Clear
  194. End Sub
  195. Sub CloseButton_Click ()
  196.   Unload Me
  197. End Sub
  198. Sub cTableList_Click ()
  199.   Dim i As Integer
  200.   Dim t As TableDef
  201.   FTbl1 = ""
  202.   FTbl2 = ""
  203.   cFieldList1.Clear
  204.   cFieldList2.Clear
  205.   For i = 0 To cTableList.ListCount - 1
  206.     If cTableList.Selected(i) Then
  207.       If FTbl1 = "" Then
  208.         FTbl1 = cTableList.List(i)
  209.       Else
  210.         FTbl2 = cTableList.List(i)
  211.         Exit For
  212.       End If
  213.     End If
  214.   Next
  215.   If FTbl2 = "" Then Exit Sub   'only one table selected
  216.   Set t = gCurrentDB.TableDefs(FTbl1)
  217.   For i = 0 To t.Fields.Count - 1
  218.     cFieldList1.AddItem t.Fields(i).Name
  219.   Next
  220.   Set t = gCurrentDB.TableDefs(FTbl2)
  221.   For i = 0 To t.Fields.Count - 1
  222.     cFieldList2.AddItem t.Fields(i).Name
  223.   Next
  224. End Sub
  225. Sub Form_Load ()
  226.   Dim i As Integer
  227.   For i = 0 To fQuery.cTableList.ListCount - 1
  228.     If fQuery.cTableList.Selected(i) Then
  229.       cTableList.AddItem fQuery.cTableList.List(i)
  230.     End If
  231.   Next
  232.   'Top = VDMDI.Top + fQuery.Top + fQuery.cCriteria.Top + 1300
  233.   'Left = fQuery.Left + 1500
  234. End Sub
  235. Sub Form_Paint ()
  236.   Outlines Me
  237. End Sub
  238.