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

  1. VERSION 5.00
  2. Begin VB.Form frmQuery 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "
  5.    ClientHeight    =   5025
  6.    ClientLeft      =   2430
  7.    ClientTop       =   2595
  8.    ClientWidth     =   7455
  9.    HelpContextID   =   2016115
  10.    Icon            =   "QUERY.frx":0000
  11.    KeyPreview      =   -1  'True
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MDIChild        =   -1  'True
  15.    ScaleHeight     =   4583.248
  16.    ScaleMode       =   0  'User
  17.    ScaleWidth      =   7358.616
  18.    ShowInTaskbar   =   0   'False
  19.    Begin VB.OptionButton optOrder 
  20.       Caption         =   "
  21.       Height          =   225
  22.       Index           =   1
  23.       Left            =   6480
  24.       MaskColor       =   &H00000000&
  25.       TabIndex        =   10
  26.       Top             =   1560
  27.       Width           =   855
  28.    End
  29.    Begin VB.OptionButton optOrder 
  30.       Caption         =   "
  31.       Height          =   221
  32.       Index           =   0
  33.       Left            =   5760
  34.       MaskColor       =   &H00000000&
  35.       TabIndex        =   9
  36.       Top             =   1560
  37.       Value           =   -1  'True
  38.       Width           =   659
  39.    End
  40.    Begin VB.CheckBox chkTopPercent 
  41.       Caption         =   "
  42.       Height          =   255
  43.       Left            =   3840
  44.       MaskColor       =   &H00000000&
  45.       TabIndex        =   15
  46.       Top             =   2880
  47.       Width           =   2175
  48.    End
  49.    Begin VB.TextBox txtTopNValue 
  50.       Height          =   285
  51.       Left            =   3000
  52.       TabIndex        =   14
  53.       Top             =   2880
  54.       Width           =   735
  55.    End
  56.    Begin VB.CommandButton cmdGetValues 
  57.       Caption         =   "
  58. (&P)"
  59.       Height          =   315
  60.       Left            =   4560
  61.       MaskColor       =   &H00000000&
  62.       TabIndex        =   5
  63.       Top             =   600
  64.       Width           =   2775
  65.    End
  66.    Begin VB.CommandButton cmdOr 
  67.       Caption         =   "
  68.  &Or"
  69.       Height          =   315
  70.       Left            =   2280
  71.       MaskColor       =   &H00000000&
  72.       TabIndex        =   4
  73.       Top             =   600
  74.       Width           =   2175
  75.    End
  76.    Begin VB.CommandButton cmdAnd 
  77.       Caption         =   "
  78.  &And"
  79.       Height          =   315
  80.       Left            =   120
  81.       MaskColor       =   &H00000000&
  82.       TabIndex        =   3
  83.       Top             =   600
  84.       Width           =   2160
  85.    End
  86.    Begin VB.ComboBox cboValue 
  87.       BackColor       =   &H00FFFFFF&
  88.       Height          =   315
  89.       Left            =   4560
  90.       Sorted          =   -1  'True
  91.       TabIndex        =   2
  92.       Text            =   "cValue"
  93.       Top             =   240
  94.       Width           =   2775
  95.    End
  96.    Begin VB.ComboBox cboOperator 
  97.       BackColor       =   &H00FFFFFF&
  98.       Height          =   315
  99.       ItemData        =   "QUERY.frx":030A
  100.       Left            =   3120
  101.       List            =   "QUERY.frx":030C
  102.       Style           =   2  'Dropdown List
  103.       TabIndex        =   1
  104.       Top             =   240
  105.       Width           =   1335
  106.    End
  107.    Begin VB.ComboBox cboField 
  108.       BackColor       =   &H00FFFFFF&
  109.       Height          =   315
  110.       Left            =   120
  111.       Style           =   2  'Dropdown List
  112.       TabIndex        =   0
  113.       Top             =   240
  114.       Width           =   2895
  115.    End
  116.    Begin VB.CommandButton cmdSaveQDF 
  117.       Caption         =   "
  118. (&V)"
  119.       Height          =   375
  120.       Left            =   3720
  121.       MaskColor       =   &H00000000&
  122.       TabIndex        =   20
  123.       Top             =   4560
  124.       Width           =   1200
  125.    End
  126.    Begin VB.CommandButton cmdJoin 
  127.       Caption         =   "
  128. (&J)"
  129.       Height          =   315
  130.       Left            =   4560
  131.       MaskColor       =   &H00000000&
  132.       TabIndex        =   12
  133.       Top             =   2160
  134.       Width           =   2775
  135.    End
  136.    Begin VB.ListBox lstJoinFields 
  137.       BackColor       =   &H00FFFFFF&
  138.       Height          =   240
  139.       Left            =   4560
  140.       TabIndex        =   13
  141.       Top             =   2522
  142.       Width           =   2775
  143.    End
  144.    Begin VB.CommandButton cmdCopySQL 
  145.       Caption         =   "
  146. (&Y)"
  147.       Height          =   375
  148.       Left            =   2520
  149.       MaskColor       =   &H00000000&
  150.       TabIndex        =   19
  151.       Top             =   4560
  152.       Width           =   1200
  153.    End
  154.    Begin VB.ComboBox cboOrderByField 
  155.       BackColor       =   &H00FFFFFF&
  156.       Height          =   315
  157.       Left            =   4560
  158.       Style           =   2  'Dropdown List
  159.       TabIndex        =   11
  160.       Top             =   1800
  161.       Width           =   2775
  162.    End
  163.    Begin VB.ComboBox cboGroupByField 
  164.       BackColor       =   &H00FFFFFF&
  165.       Height          =   315
  166.       Left            =   4560
  167.       Style           =   2  'Dropdown List
  168.       TabIndex        =   8
  169.       Top             =   1200
  170.       Width           =   2775
  171.    End
  172.    Begin VB.ListBox lstTables 
  173.       BackColor       =   &H00FFFFFF&
  174.       Height          =   1320
  175.       Left            =   120
  176.       MultiSelect     =   1  'Simple
  177.       TabIndex        =   6
  178.       Top             =   1200
  179.       Width           =   1815
  180.    End
  181.    Begin VB.CommandButton cmdShowSQL 
  182.       Caption         =   "
  183. (&S)"
  184.       Height          =   375
  185.       Left            =   1320
  186.       MaskColor       =   &H00000000&
  187.       TabIndex        =   18
  188.       Top             =   4560
  189.       Width           =   1200
  190.    End
  191.    Begin VB.ListBox lstShowFields 
  192.       BackColor       =   &H00FFFFFF&
  193.       Height          =   1320
  194.       Left            =   2040
  195.       MultiSelect     =   1  'Simple
  196.       TabIndex        =   7
  197.       Top             =   1200
  198.       Width           =   2295
  199.    End
  200.    Begin VB.CommandButton cmdClose 
  201.       Cancel          =   -1  'True
  202.       Caption         =   "
  203. (&C)"
  204.       Height          =   375
  205.       Left            =   6120
  206.       MaskColor       =   &H00000000&
  207.       TabIndex        =   22
  208.       Top             =   4560
  209.       Width           =   1200
  210.    End
  211.    Begin VB.CommandButton cmdRunQuery 
  212.       Caption         =   "
  213. (&R)"
  214.       Height          =   375
  215.       Left            =   120
  216.       MaskColor       =   &H00000000&
  217.       TabIndex        =   17
  218.       Top             =   4560
  219.       Width           =   1200
  220.    End
  221.    Begin VB.CommandButton cmdClear 
  222.       Caption         =   "
  223. (&L)"
  224.       Height          =   375
  225.       Left            =   4920
  226.       MaskColor       =   &H00000000&
  227.       TabIndex        =   21
  228.       Top             =   4560
  229.       Width           =   1200
  230.    End
  231.    Begin VB.TextBox txtCriteria 
  232.       BackColor       =   &H00FFFFFF&
  233.       Height          =   1215
  234.       Left            =   120
  235.       MultiLine       =   -1  'True
  236.       ScrollBars      =   2  'Vertical
  237.       TabIndex        =   16
  238.       Top             =   3240
  239.       Width           =   7215
  240.    End
  241.    Begin VB.Label lblLabels 
  242.       Alignment       =   1  'Right Justify
  243.       Caption         =   "
  244.       Height          =   195
  245.       Index           =   7
  246.       Left            =   840
  247.       TabIndex        =   31
  248.       Top             =   2910
  249.       Width           =   2175
  250.    End
  251.    Begin VB.Label lblLabels 
  252.       AutoSize        =   -1  'True
  253.       Caption         =   "
  254.       Height          =   195
  255.       Index           =   1
  256.       Left            =   3120
  257.       TabIndex        =   30
  258.       Top             =   0
  259.       Width           =   720
  260.    End
  261.    Begin VB.Label lblLabels 
  262.       AutoSize        =   -1  'True
  263.       Caption         =   "
  264.       Height          =   195
  265.       Index           =   2
  266.       Left            =   4560
  267.       TabIndex        =   29
  268.       Top             =   0
  269.       Width           =   450
  270.    End
  271.    Begin VB.Label lblLabels 
  272.       AutoSize        =   -1  'True
  273.       Caption         =   "
  274.       Height          =   195
  275.       Index           =   0
  276.       Left            =   120
  277.       TabIndex        =   28
  278.       Top             =   0
  279.       Width           =   840
  280.    End
  281.    Begin VB.Label lblLabels 
  282.       AutoSize        =   -1  'True
  283.       Caption         =   "
  284.       Height          =   195
  285.       Index           =   6
  286.       Left            =   4560
  287.       TabIndex        =   27
  288.       Top             =   1560
  289.       Width           =   750
  290.    End
  291.    Begin VB.Label lblLabels 
  292.       AutoSize        =   -1  'True
  293.       Caption         =   "
  294.       Height          =   195
  295.       Index           =   5
  296.       Left            =   4560
  297.       TabIndex        =   26
  298.       Top             =   960
  299.       Width           =   765
  300.    End
  301.    Begin VB.Label lblLabels 
  302.       AutoSize        =   -1  'True
  303.       Caption         =   "
  304.       Height          =   195
  305.       Index           =   3
  306.       Left            =   120
  307.       TabIndex        =   25
  308.       Top             =   960
  309.       Width           =   570
  310.    End
  311.    Begin VB.Label lblLabels 
  312.       AutoSize        =   -1  'True
  313.       Caption         =   "
  314.       Height          =   195
  315.       Index           =   4
  316.       Left            =   2040
  317.       TabIndex        =   24
  318.       Top             =   960
  319.       Width           =   1140
  320.    End
  321.    Begin VB.Label lblLabels 
  322.       AutoSize        =   -1  'True
  323.       Caption         =   "
  324.       Height          =   195
  325.       Index           =   8
  326.       Left            =   120
  327.       TabIndex        =   23
  328.       Top             =   3000
  329.       Width           =   630
  330.    End
  331. Attribute VB_Name = "frmQuery"
  332. Attribute VB_GlobalNameSpace = False
  333. Attribute VB_Creatable = False
  334. Attribute VB_PredeclaredId = True
  335. Attribute VB_Exposed = False
  336. Option Explicit
  337. '>>>>>>>>>>>>>>>>>>>>>>>>
  338. Const FORMCAPTION = "
  339. Const BUTTON1 = "
  340.  &And"
  341. Const BUTTON2 = "
  342.  &Or"
  343. Const BUTTON3 = "
  344. (&P)"
  345. Const BUTTON4 = "
  346. Const BUTTON5 = "
  347. (&R)"
  348. Const BUTTON6 = "
  349. (&S)"
  350. Const BUTTON7 = "
  351. (&Y)"
  352. Const BUTTON8 = "
  353. (&V)"
  354. Const BUTTON9 = "
  355. (&L)"
  356. Const BUTTON10 = "
  357. (&C)"
  358. Const Label1 = "
  359. Const Label2 = "
  360. Const LABEL3 = "
  361. Const LABEL4 = "
  362. Const LABEL5 = "
  363. Const LABEL6 = "
  364. Const LABEL7 = "
  365. Const LABEL8 = "
  366. Const LABEL9 = "
  367. Const CHECK1 = "
  368. Const MSG1 = "
  369. Const MSG2 = "
  370. Const MSG3 = "
  371. Const MSG4 = "
  372. Const MSG5 = "
  373. Const MSG6 = "
  374. Const MSG7 = "
  375. Const MSG8 = "
  376. '>>>>>>>>>>>>>>>>>>>>>>>>
  377. Dim mbShowSQL As Integer
  378. Dim mbCopySQL As Integer
  379. Dim mbSaveSQL As Integer
  380. Private Sub cmdAnd_Click()
  381.   Dim nFldType As Integer
  382.   Dim sFieldName As String
  383.   Dim sTableName As String
  384.   If Len(cboField.Text) = 0 Then Exit Sub
  385.   sTableName = stSTF((cboField), 0)
  386.   sFieldName = stSTF((cboField), 1)
  387.   nFldType = gdbCurrentDB.TableDefs(StripBrackets(sTableName)).Fields(StripBrackets(sFieldName)).Type
  388.   If Len(txtCriteria.Text) > 0 Then
  389.     txtCriteria.Text = txtCriteria.Text & vbCrLf & "And "
  390.   End If
  391.   If nFldType = dbText Or nFldType = dbMemo Or nFldType = dbDate Then
  392.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " '" & cboValue.Text & "'"
  393.   Else
  394.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " " & cboValue.Text
  395.   End If
  396.   cboField.SetFocus
  397. End Sub
  398. Private Sub cboField_Click()
  399.   cboValue.Clear
  400. End Sub
  401. Private Sub cmdClear_Click()
  402.   On Error Resume Next
  403.   Dim i As Integer
  404.   For i = 0 To lstTables.ListCount - 1
  405.     lstTables.Selected(i) = False
  406.   Next
  407.   txtCriteria.Text = vbNullString
  408.   txtTopNValue.Text = vbNullString
  409. End Sub
  410. Private Sub cmdClose_Click()
  411.   Unload Me
  412. End Sub
  413. Private Sub cmdCopySQL_Click()
  414.   mbCopySQL = True
  415.   Call cmdRunQuery_Click
  416.   mbCopySQL = False
  417. End Sub
  418. Private Sub cmdSaveQDF_Click()
  419.   mbSaveSQL = True
  420.   Call cmdRunQuery_Click
  421.   mbSaveSQL = False
  422. End Sub
  423. Private Sub lstTables_Click()
  424.   On Error GoTo LTErr
  425.   Dim i As Integer, ii As Integer
  426.   Dim tdf As TableDef
  427.   Dim qdf As QueryDef
  428.   Dim sTmp As String
  429.   Dim fld As Field
  430.   MsgBar MSG1, True
  431.   cboField.Clear
  432.   lstShowFields.Clear
  433.   cboGroupByField.Clear
  434.   cboOrderByField.Clear
  435.   cboValue.Clear
  436.   cboGroupByField.AddItem MSG2
  437.   cboOrderByField.AddItem MSG2
  438.   For ii = 0 To lstTables.ListCount - 1
  439.     If lstTables.Selected(ii) Then
  440.       If lstTables.ItemData(ii) = 0 Then
  441.         '
  442.         Set tdf = gdbCurrentDB.TableDefs(lstTables.List(ii))
  443.         For Each fld In tdf.Fields
  444.           sTmp = AddBrackets((lstTables.List(ii))) & "." & AddBrackets((fld.Name))
  445.           cboField.AddItem sTmp
  446.           lstShowFields.AddItem sTmp
  447.           cboGroupByField.AddItem sTmp
  448.           cboOrderByField.AddItem sTmp
  449.         Next
  450.       Else
  451.         '
  452.         Set qdf = gdbCurrentDB.QueryDefs(lstTables.List(ii))
  453.         For Each fld In qdf.Fields
  454.           sTmp = AddBrackets((lstTables.List(ii))) & "." & AddBrackets((fld.Name))
  455.           cboField.AddItem sTmp
  456.           lstShowFields.AddItem sTmp
  457.           cboGroupByField.AddItem sTmp
  458.           cboOrderByField.AddItem sTmp
  459.         Next
  460.       End If
  461.     End If
  462.   Next
  463.   If Len(cboField.List(0)) > 0 Then
  464.     cboField.ListIndex = 0
  465.     cboGroupByField.ListIndex = 0
  466.     cboOrderByField.ListIndex = 0
  467.   End If
  468.   MsgBar vbNullString, False
  469.   Exit Sub
  470. LTErr:
  471.   ShowError
  472. End Sub
  473. Private Sub Form_Load()
  474.   On Local Error GoTo FLErr
  475.   Dim rec As Recordset
  476.   Dim i As Integer
  477.   Me.Caption = FORMCAPTION
  478.   cmdAnd.Caption = BUTTON1
  479.   cmdOr.Caption = BUTTON2
  480.   cmdGetValues.Caption = BUTTON3
  481.   cmdJoin.Caption = BUTTON4
  482.   cmdRunQuery.Caption = BUTTON5
  483.   cmdShowSQL.Caption = BUTTON6
  484.   cmdCopySQL.Caption = BUTTON7
  485.   cmdSaveQDF.Caption = BUTTON8
  486.   cmdClear.Caption = BUTTON9
  487.   cmdClose.Caption = BUTTON10
  488.   lblLabels(0).Caption = Label1
  489.   lblLabels(1).Caption = Label2
  490.   lblLabels(2).Caption = LABEL3
  491.   lblLabels(3).Caption = LABEL4
  492.   lblLabels(4).Caption = LABEL5
  493.   lblLabels(5).Caption = LABEL6
  494.   lblLabels(6).Caption = LABEL7
  495.   lblLabels(7).Caption = LABEL8
  496.   lblLabels(8).Caption = LABEL9
  497.   chkTopPercent.Caption = CHECK1
  498.   txtCriteria.Text = vbNullString
  499.   cboOperator.AddItem "="
  500.   cboOperator.AddItem "<>"
  501.   cboOperator.AddItem ">"
  502.   cboOperator.AddItem ">="
  503.   cboOperator.AddItem "<"
  504.   cboOperator.AddItem "<="
  505.   cboOperator.AddItem "Like"
  506.   cboOperator.ListIndex = 0
  507.   GetTableList lstTables, True, False, True
  508.   lstTables.ListIndex = 0
  509.   cboValue.Text = vbNullString
  510.   Height = 5520
  511.   Width = 7224
  512.   Left = (frmMDI.Width - Width) / 2
  513.   Top = 0
  514.   Exit Sub
  515. FLErr:
  516.   ShowError
  517. End Sub
  518. Private Sub Form_Resize()
  519.   On Error Resume Next
  520.   If WindowState <> 1 Then
  521.     Me.Height = 5430
  522.     Me.Width = 7575
  523.   End If
  524. End Sub
  525. Private Sub cmdGetValues_Click()
  526.   On Error GoTo GVErr
  527.   Dim rec As Recordset
  528.   MsgBar "
  529. ", True
  530.   Screen.MousePointer = vbHourglass
  531.   Set rec = gdbCurrentDB.OpenRecordset("select Distinct " & cboField & " from " & stSTF((cboField), 0))
  532.   Do While rec.EOF = False
  533.     If Len(Trim(rec(0))) > 0 Then
  534.       cboValue.AddItem rec(0).Value
  535.     End If
  536.     rec.MoveNext
  537.   Loop
  538.   rec.Close
  539.   cboValue.Text = cboValue.List(0)
  540.   cboValue.SetFocus
  541.   Screen.MousePointer = vbDefault
  542.   MsgBar vbNullString, False
  543.   Exit Sub
  544. GVErr:
  545.   Screen.MousePointer = vbDefault
  546.   MsgBar vbNullString, False
  547.   cboValue.Text = vbNullString
  548.   Exit Sub
  549. End Sub
  550. Private Sub cmdJoin_Click()
  551.   Dim i As Integer
  552.   Dim c As Integer
  553.   For i = 0 To lstTables.ListCount - 1
  554.     If lstTables.Selected(i) Then
  555.       c = c + 1
  556.     End If
  557.   Next
  558.   If c < 2 Then
  559.     Beep
  560.     MsgBox MSG3, 48
  561.   Else
  562.     MsgBar MSG4, False
  563.     frmJoin.Show vbModal
  564.     MsgBar vbNullString, False
  565.   End If
  566. End Sub
  567. Private Sub cmdOr_Click()
  568.   Dim nType As Integer
  569.   Dim sFieldName As String
  570.   Dim sTableName As String
  571.   If Len(cboField.Text) = 0 Then Exit Sub
  572.   sTableName = stSTF((cboField), 0)
  573.   sFieldName = stSTF((cboField), 1)
  574.   nType = gdbCurrentDB.TableDefs(StripBrackets(sTableName)).Fields(StripBrackets(sFieldName)).Type
  575.   If Len(txtCriteria.Text) > 0 Then
  576.     txtCriteria.Text = txtCriteria.Text & vbCrLf & " Or "
  577.   End If
  578.   If nType = dbText Or nType = dbMemo Or nType = dbDate Then
  579.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " '" & cboValue.Text & "'"
  580.   Else
  581.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " " & cboValue.Text
  582.   End If
  583.   cboField.SetFocus
  584. End Sub
  585. Private Sub cmdRunQuery_Click()
  586.   On Error GoTo OKErr
  587.   Dim rsTmp As Recordset
  588.   Dim frmTmp As Form
  589.   Dim fs As String
  590.   Dim ts As String
  591.   Dim i As Integer
  592.   Dim sWhere As String
  593.   Dim sWhere2 As String
  594.   Dim sNewWhere As String
  595.   Dim sTmp As String
  596.   Dim bMatchParen As Integer
  597.   Dim sQueryName As String
  598.   Dim qdfTmp As QueryDef
  599.   Dim sSQLString As String
  600.   If lstShowFields.ListCount = 0 Then
  601.     MsgBox MSG5, vbExclamation
  602.     Exit Sub
  603.   End If
  604.   MsgBar MSG6, True
  605.   If Len(txtCriteria.Text) > 0 Then
  606.     sWhere = "AND " & LTrim(txtCriteria.Text)
  607.     '
  608.  vbcrlfs
  609.     For i = 1 To Len(sWhere)
  610.       If Mid(sWhere, i, 1) = Chr(13) Then
  611.         sTmp = sTmp & " "
  612.       ElseIf Mid(sWhere, i, 1) = Chr(10) Then
  613.         '
  614.       Else
  615.         sTmp = sTmp + Mid(sWhere, i, 1)
  616.       End If
  617.     Next
  618.     sWhere = sTmp
  619.     sWhere = RTrim(sWhere)
  620.     '
  621.  sWhere 
  622.      sWhere2 = sWhere
  623.      Do
  624.        sTmp = stGetToken(sWhere2, " ")
  625.        sTmp = sTmp & " "
  626.         If bMatchParen = False And UCase(sTmp) = "AND " Then
  627.          sNewWhere = sNewWhere + sTmp & "("
  628.          bMatchParen = True
  629.        ElseIf bMatchParen And UCase(sTmp) = "AND " Then
  630.          sNewWhere = sNewWhere & ") " & sTmp & "("
  631.          'bMatchParen = False
  632.        Else
  633.          If UCase(sTmp) = "OR" Or UCase(sTmp) = "IN " Or UCase(sTmp) = "LIKE" Then
  634.            sNewWhere = sNewWhere & " " & sTmp
  635.          Else
  636.            sNewWhere = sNewWhere + sTmp
  637.          End If
  638.        End If
  639.      Loop Until sWhere2 = vbNullString
  640.      sWhere = sNewWhere & ")"
  641.     '
  642.     '
  643.  AND/OR
  644.     If Mid(sWhere, 2, 2) = "OR" Then
  645.       sWhere = Mid(sWhere, 5, Len(sWhere) - 5)
  646.     Else
  647.       sTmp = stGetToken(sWhere, " ")
  648.     End If
  649.     If Len(sWhere) > 0 Then
  650.       sWhere = " Where " & sWhere
  651.     End If
  652.   End If
  653.   If lstJoinFields.ListCount > 0 Then
  654.     If Len(sWhere) = 0 Then
  655.       sWhere = sWhere & " Where "
  656.     Else
  657.       sWhere = sWhere & " And "
  658.     End If
  659.     For i = 0 To lstJoinFields.ListCount - 1
  660.       sWhere = sWhere + lstJoinFields.List(i) & " And "
  661.     Next
  662.     sWhere = Mid(sWhere, 1, Len(sWhere) - 5)
  663.   End If
  664.   If cboGroupByField <> MSG2 Then
  665.     sWhere = sWhere & " Group By " & cboGroupByField
  666.   End If
  667.   If cboOrderByField <> MSG2 Then
  668.     sWhere = sWhere & " Order By " & cboOrderByField
  669.     If optOrder(1).Value Then
  670.       sWhere = sWhere & " Desc "
  671.     End If
  672.   End If
  673.   For i% = 0 To lstShowFields.ListCount - 1
  674.     If lstShowFields.Selected(i%) Then
  675.       fs = fs + lstShowFields.List(i%) & ","
  676.     End If
  677.   Next
  678.   If Len(fs) = 0 Then
  679.     For i% = 0 To lstTables.ListCount - 1
  680.       If lstTables.Selected(i%) Then
  681.         fs = fs + AddBrackets((lstTables.List(i%))) & ".*,"
  682.       End If
  683.     Next
  684.     If Len(fs) = 0 Then
  685.       fs = "*"
  686.     Else
  687.       fs = Mid(fs, 1, Len(fs) - 1)     '
  688.     End If
  689.   Else
  690.     fs = Mid(fs, 1, Len(fs) - 1)
  691.   End If
  692.   For i% = 0 To lstTables.ListCount - 1
  693.     If lstTables.Selected(i%) Then
  694.       ts = ts + AddBrackets((lstTables.List(i%))) & ","
  695.     End If
  696.   Next
  697.   ts = Mid(ts, 1, Len(ts) - 1)
  698.   sSQLString = "Select "
  699.   If Len(txtTopNValue.Text) > 0 Then
  700.     sSQLString = sSQLString & " TOP " & txtTopNValue.Text & " "
  701.     If chkTopPercent.Value = vbChecked Then
  702.       sSQLString = sSQLString & " PERCENT "
  703.     End If
  704.   End If
  705.   sSQLString = sSQLString & fs & " From " & ts + sWhere
  706.   If mbShowSQL = False And mbCopySQL = False And mbSaveSQL = False Then
  707.     MsgBar MSG7, True
  708.     OpenQuery sSQLString, True
  709.   ElseIf mbShowSQL Then
  710.     MsgBar vbNullString, False
  711.     MsgBox sSQLString, 0, "SQL 
  712.   ElseIf mbCopySQL Then
  713.     frmSQL.txtSQLStatement.Text = sSQLString
  714.   ElseIf mbSaveSQL Then
  715.     MsgBar vbNullString, False
  716.     sQueryName = InputBox(MSG8)
  717.     If Len(sQueryName) = 0 Then Exit Sub
  718.     '
  719.     If DupeTableName(sQueryName) Then
  720.       Exit Sub
  721.     End If
  722.     '
  723.     Set qdfTmp = gdbCurrentDB.CreateQueryDef(sQueryName, sSQLString)
  724.     RefreshTables Nothing
  725.   End If
  726.   MsgBar vbNullString, False
  727.   Exit Sub
  728. OKErr:
  729.   If Err = 364 Then Exit Sub   '
  730.   ShowError
  731. End Sub
  732. Private Sub cmdShowSQL_Click()
  733.   mbShowSQL = True
  734.   Call cmdRunQuery_Click
  735.   mbShowSQL = False
  736. End Sub
  737. Private Function stGetToken(rsLine As String, rsDelim As String) As String
  738.   On Error GoTo GetTokenError
  739.   Dim iOpenQuote As Integer
  740.   Dim iCloseQuote As Integer
  741.   Dim iDelim As Integer
  742.   Dim stToken As String
  743.   iOpenQuote = InStr(1, rsLine, """")
  744.   iDelim = InStr(1, rsLine, rsDelim)
  745.   If (iOpenQuote > 0) And (iOpenQuote < iDelim) Then
  746.     iCloseQuote = InStr(iOpenQuote + 1, rsLine, """")
  747.     iDelim = InStr(iCloseQuote + 1, rsLine, rsDelim)
  748.   End If
  749.   If (iDelim% <> 0) Then
  750.     stToken = LTrim(RTrim(Mid(rsLine, 1, iDelim - 1)))
  751.     rsLine = Mid(rsLine, iDelim + 1)
  752.   Else
  753.     stToken = LTrim(RTrim(Mid(rsLine, 1)))
  754.     rsLine = vbNullString
  755.   End If
  756.   If (Len(stToken) > 0) Then
  757.     If (Mid(stToken, 1, 1) = """") Then
  758.       stToken = Mid(stToken, 2)
  759.     End If
  760.     If (Mid(stToken, Len(stToken), 1) = """") Then
  761.       stToken = Mid(stToken, 1, Len(stToken) - 1)
  762.     End If
  763.   End If
  764.   stGetToken = stToken
  765.   Exit Function
  766. GetTokenError:
  767.   Exit Function
  768. End Function
  769.  tbl.fld 
  770. Private Function stSTF(rsName As String, rnPart As Integer) As String
  771.   If InStr(InStr(1, rsName, ".") + 1, rsName, ".") > 1 Then
  772.     rsName = StripOwner(rsName)
  773.   End If
  774.   If rnPart = 0 Then
  775.     stSTF = Mid(rsName, 1, InStr(1, rsName, ".") - 1)
  776.   Else
  777.     stSTF = Mid(rsName, InStr(1, rsName, ".") + 1, Len(rsName))
  778.   End If
  779. End Function
  780.