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

  1. VERSION 4.00
  2. Begin VB.Form frmQuery 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Query Builder"
  5.    ClientHeight    =   5025
  6.    ClientLeft      =   1230
  7.    ClientTop       =   1500
  8.    ClientWidth     =   7455
  9.    Height          =   5430
  10.    HelpContextID   =   2016115
  11.    Icon            =   "QUERY.frx":0000
  12.    KeyPreview      =   -1  'True
  13.    Left            =   1170
  14.    LinkTopic       =   "Form1"
  15.    LockControls    =   -1  'True
  16.    MaxButton       =   0   'False
  17.    MDIChild        =   -1  'True
  18.    ScaleHeight     =   5007.369
  19.    ScaleMode       =   0  'User
  20.    ScaleWidth      =   7477.065
  21.    Top             =   1155
  22.    Width           =   7575
  23.    Begin VB.OptionButton optOrder 
  24.       Caption         =   "Desc"
  25.       Height          =   225
  26.       Index           =   1
  27.       Left            =   6480
  28.       TabIndex        =   10
  29.       Top             =   1560
  30.       Width           =   855
  31.    End
  32.    Begin VB.OptionButton optOrder 
  33.       Caption         =   "Asc"
  34.       Height          =   221
  35.       Index           =   0
  36.       Left            =   5760
  37.       TabIndex        =   9
  38.       Top             =   1560
  39.       Value           =   -1  'True
  40.       Width           =   615
  41.    End
  42.    Begin VB.CheckBox chkTopPercent 
  43.       Caption         =   "Top Percent"
  44.       Height          =   255
  45.       Left            =   3840
  46.       TabIndex        =   15
  47.       Top             =   2880
  48.       Width           =   2175
  49.    End
  50.    Begin VB.TextBox txtTopNValue 
  51.       Height          =   285
  52.       Left            =   3000
  53.       TabIndex        =   14
  54.       Top             =   2880
  55.       Width           =   735
  56.    End
  57.    Begin VB.CommandButton cmdGetValues 
  58.       Caption         =   "List &Possible Values"
  59.       Height          =   315
  60.       Left            =   4560
  61.       TabIndex        =   5
  62.       Top             =   600
  63.       Width           =   2775
  64.    End
  65.    Begin VB.CommandButton cmdOr 
  66.       Caption         =   "&Or into Criteria"
  67.       Height          =   315
  68.       Left            =   2280
  69.       TabIndex        =   4
  70.       Top             =   600
  71.       Width           =   2175
  72.    End
  73.    Begin VB.CommandButton cmdAnd 
  74.       Caption         =   "&And into Criteria"
  75.       Height          =   315
  76.       Left            =   120
  77.       TabIndex        =   3
  78.       Top             =   600
  79.       Width           =   2175
  80.    End
  81.    Begin VB.ComboBox cboValue 
  82.       BackColor       =   &H00FFFFFF&
  83.       Height          =   300
  84.       Left            =   4560
  85.       Sorted          =   -1  'True
  86.       TabIndex        =   2
  87.       Text            =   "cValue"
  88.       Top             =   240
  89.       Width           =   2775
  90.    End
  91.    Begin VB.ComboBox cboOperator 
  92.       BackColor       =   &H00FFFFFF&
  93.       Height          =   300
  94.       ItemData        =   "QUERY.frx":030A
  95.       Left            =   3120
  96.       List            =   "QUERY.frx":0323
  97.       Style           =   2  'Dropdown List
  98.       TabIndex        =   1
  99.       Top             =   240
  100.       Width           =   1335
  101.    End
  102.    Begin VB.ComboBox cboField 
  103.       BackColor       =   &H00FFFFFF&
  104.       Height          =   300
  105.       Left            =   120
  106.       Style           =   2  'Dropdown List
  107.       TabIndex        =   0
  108.       Top             =   240
  109.       Width           =   2895
  110.    End
  111.    Begin VB.CommandButton cmdSaveQDF 
  112.       Caption         =   "Sa&ve"
  113.       Height          =   375
  114.       Left            =   3720
  115.       TabIndex        =   20
  116.       Top             =   4560
  117.       Width           =   1215
  118.    End
  119.    Begin VB.CommandButton cmdJoin 
  120.       Caption         =   "Set Table &Joins"
  121.       Height          =   255
  122.       Left            =   4560
  123.       TabIndex        =   12
  124.       Top             =   2160
  125.       Width           =   2775
  126.    End
  127.    Begin VB.ListBox lstJoinFields 
  128.       BackColor       =   &H00FFFFFF&
  129.       Height          =   420
  130.       Left            =   4560
  131.       TabIndex        =   13
  132.       Top             =   2400
  133.       Width           =   2775
  134.    End
  135.    Begin VB.CommandButton cmdCopySQL 
  136.       Caption         =   "Cop&y"
  137.       Height          =   375
  138.       Left            =   2520
  139.       TabIndex        =   19
  140.       Top             =   4560
  141.       Width           =   1215
  142.    End
  143.    Begin VB.ComboBox cboOrderByField 
  144.       BackColor       =   &H00FFFFFF&
  145.       Height          =   300
  146.       Left            =   4560
  147.       Style           =   2  'Dropdown List
  148.       TabIndex        =   11
  149.       Top             =   1800
  150.       Width           =   2775
  151.    End
  152.    Begin VB.ComboBox cboGroupByField 
  153.       BackColor       =   &H00FFFFFF&
  154.       Height          =   300
  155.       Left            =   4560
  156.       Style           =   2  'Dropdown List
  157.       TabIndex        =   8
  158.       Top             =   1200
  159.       Width           =   2775
  160.    End
  161.    Begin VB.ListBox lstTables 
  162.       BackColor       =   &H00FFFFFF&
  163.       Height          =   1590
  164.       Left            =   120
  165.       MultiSelect     =   1  'Simple
  166.       TabIndex        =   6
  167.       Top             =   1200
  168.       Width           =   1815
  169.    End
  170.    Begin VB.CommandButton cmdShowSQL 
  171.       Caption         =   "&Show"
  172.       Height          =   375
  173.       Left            =   1320
  174.       TabIndex        =   18
  175.       Top             =   4560
  176.       Width           =   1215
  177.    End
  178.    Begin VB.ListBox lstShowFields 
  179.       BackColor       =   &H00FFFFFF&
  180.       Height          =   1590
  181.       Left            =   2040
  182.       MultiSelect     =   1  'Simple
  183.       TabIndex        =   7
  184.       Top             =   1200
  185.       Width           =   2295
  186.    End
  187.    Begin VB.CommandButton cmdClose 
  188.       Cancel          =   -1  'True
  189.       Caption         =   "&Close"
  190.       Height          =   375
  191.       Left            =   6120
  192.       TabIndex        =   22
  193.       Top             =   4560
  194.       Width           =   1215
  195.    End
  196.    Begin VB.CommandButton cmdRunQuery 
  197.       Caption         =   "&Run"
  198.       Height          =   375
  199.       Left            =   120
  200.       TabIndex        =   17
  201.       Top             =   4560
  202.       Width           =   1215
  203.    End
  204.    Begin VB.CommandButton cmdClear 
  205.       Caption         =   "C&lear"
  206.       Height          =   375
  207.       Left            =   4920
  208.       TabIndex        =   21
  209.       Top             =   4560
  210.       Width           =   1215
  211.    End
  212.    Begin VB.TextBox txtCriteria 
  213.       BackColor       =   &H00FFFFFF&
  214.       Height          =   1215
  215.       Left            =   120
  216.       MultiLine       =   -1  'True
  217.       ScrollBars      =   2  'Vertical
  218.       TabIndex        =   16
  219.       Top             =   3240
  220.       Width           =   7215
  221.    End
  222.    Begin VB.Label lblTopN 
  223.       Caption         =   "Top N Value:"
  224.       Height          =   195
  225.       Left            =   1440
  226.       TabIndex        =   31
  227.       Top             =   2910
  228.       Width           =   1470
  229.    End
  230.    Begin VB.Label lblOperator 
  231.       AutoSize        =   -1  'True
  232.       Caption         =   "Operator:"
  233.       Height          =   195
  234.       Left            =   3120
  235.       TabIndex        =   30
  236.       Top             =   0
  237.       Width           =   660
  238.    End
  239.    Begin VB.Label lblValue 
  240.       AutoSize        =   -1  'True
  241.       Caption         =   "Value:"
  242.       Height          =   195
  243.       Left            =   4560
  244.       TabIndex        =   29
  245.       Top             =   0
  246.       Width           =   450
  247.    End
  248.    Begin VB.Label lblFieldName 
  249.       AutoSize        =   -1  'True
  250.       Caption         =   "Field Name:"
  251.       Height          =   195
  252.       Left            =   120
  253.       TabIndex        =   28
  254.       Top             =   0
  255.       Width           =   840
  256.    End
  257.    Begin VB.Label lblOrberByField 
  258.       AutoSize        =   -1  'True
  259.       Caption         =   "Order By: "
  260.       Height          =   195
  261.       Left            =   4560
  262.       TabIndex        =   27
  263.       Top             =   1560
  264.       Width           =   705
  265.    End
  266.    Begin VB.Label lblGroupByField 
  267.       AutoSize        =   -1  'True
  268.       Caption         =   "Group By: "
  269.       Height          =   195
  270.       Left            =   4560
  271.       TabIndex        =   26
  272.       Top             =   960
  273.       Width           =   750
  274.    End
  275.    Begin VB.Label lblTableList 
  276.       AutoSize        =   -1  'True
  277.       Caption         =   "Tables: "
  278.       Height          =   195
  279.       Left            =   120
  280.       TabIndex        =   25
  281.       Top             =   960
  282.       Width           =   570
  283.    End
  284.    Begin VB.Label lblShowFields 
  285.       AutoSize        =   -1  'True
  286.       Caption         =   "Fields to Show: "
  287.       Height          =   195
  288.       Left            =   2040
  289.       TabIndex        =   24
  290.       Top             =   960
  291.       Width           =   1125
  292.    End
  293.    Begin VB.Label lblCriteria 
  294.       AutoSize        =   -1  'True
  295.       Caption         =   "Criteria: "
  296.       Height          =   195
  297.       Left            =   120
  298.       TabIndex        =   23
  299.       Top             =   3000
  300.       Width           =   570
  301.    End
  302. Attribute VB_Name = "frmQuery"
  303. Attribute VB_Creatable = False
  304. Attribute VB_Exposed = False
  305. Option Explicit
  306. Dim mbShowSQL As Integer
  307. Dim mbCopySQL As Integer
  308. Dim mbSaveSQL As Integer
  309. Private Sub cmdAnd_Click()
  310.   Dim nFldType As Integer
  311.   Dim sFieldName As String
  312.   Dim sTableName As String
  313.   If Len(cboField.Text) = 0 Then Exit Sub
  314.   sTableName = stSTF((cboField), 0)
  315.   sFieldName = stSTF((cboField), 1)
  316.   nFldType = gdbCurrentDB.TableDefs(StripBrackets(sTableName)).Fields(StripBrackets(sFieldName)).Type
  317.   If Len(txtCriteria.Text) > 0 Then
  318.     txtCriteria.Text = txtCriteria.Text & gsNewLine & "And "
  319.   End If
  320.   If nFldType = dbText Or nFldType = dbMemo Or nFldType = dbDate Then
  321.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " '" & cboValue.Text & "'"
  322.   Else
  323.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " " & cboValue.Text
  324.   End If
  325.   cboField.SetFocus
  326. End Sub
  327. Private Sub cboField_Click()
  328.   cboValue.Clear
  329. End Sub
  330. Private Sub cmdClear_Click()
  331.   On Error Resume Next
  332.   Dim i As Integer
  333.   For i = 0 To lstTables.ListCount - 1
  334.     lstTables.Selected(i) = False
  335.   Next
  336.   txtCriteria.Text = gsNULL_STR
  337.   txtTopNValue.Text = gsNULL_STR
  338. End Sub
  339. Private Sub cmdClose_Click()
  340.   Unload Me
  341. End Sub
  342. Private Sub cmdCopySQL_Click()
  343.   mbCopySQL = True
  344.   Call cmdRunQuery_Click
  345.   mbCopySQL = False
  346. End Sub
  347. Private Sub cmdSaveQDF_Click()
  348.   mbSaveSQL = True
  349.   Call cmdRunQuery_Click
  350.   mbSaveSQL = False
  351. End Sub
  352. Private Sub lstTables_Click()
  353.   On Error GoTo LTErr
  354.   Dim i As Integer, ii As Integer
  355.   Dim tdf As TableDef
  356.   Dim qdf As QueryDef
  357.   Dim sTmp As String
  358.   Dim fld As Field
  359.   MsgBar "Updating Form Fields", True
  360.   cboField.Clear
  361.   lstShowFields.Clear
  362.   cboGroupByField.Clear
  363.   cboOrderByField.Clear
  364.   cboValue.Clear
  365.   cboGroupByField.AddItem "(none)"
  366.   cboOrderByField.AddItem "(none)"
  367.   For ii = 0 To lstTables.ListCount - 1
  368.     If lstTables.Selected(ii) Then
  369.       If lstTables.ItemData(ii) = 0 Then
  370.         'must be a table
  371.         Set tdf = gdbCurrentDB.TableDefs(lstTables.List(ii))
  372.         For Each fld In tdf.Fields
  373.           sTmp = AddBrackets((lstTables.List(ii))) & "." & AddBrackets((fld.Name))
  374.           cboField.AddItem sTmp
  375.           lstShowFields.AddItem sTmp
  376.           cboGroupByField.AddItem sTmp
  377.           cboOrderByField.AddItem sTmp
  378.         Next
  379.       Else
  380.         'must be a querydef
  381.         Set qdf = gdbCurrentDB.QueryDefs(lstTables.List(ii))
  382.         For Each fld In qdf.Fields
  383.           sTmp = AddBrackets((lstTables.List(ii))) & "." & AddBrackets((fld.Name))
  384.           cboField.AddItem sTmp
  385.           lstShowFields.AddItem sTmp
  386.           cboGroupByField.AddItem sTmp
  387.           cboOrderByField.AddItem sTmp
  388.         Next
  389.       End If
  390.     End If
  391.   Next
  392.   If Len(cboField.List(0)) > 0 Then
  393.     cboField.ListIndex = 0
  394.     cboGroupByField.ListIndex = 0
  395.     cboOrderByField.ListIndex = 0
  396.   End If
  397.   MsgBar gsNULL_STR, False
  398.   Exit Sub
  399. LTErr:
  400.   ShowError
  401.   Exit Sub
  402. End Sub
  403. Private Sub Form_Load()
  404.   On Local Error GoTo FLErr
  405.   Dim rec As Recordset
  406.   Dim i As Integer
  407.   'Clear listbox
  408.   txtCriteria.Text = gsNULL_STR
  409.   cboOperator.ListIndex = 0
  410.   'fill the table list
  411.   GetTableList lstTables, True, False, True
  412.   lstTables.ListIndex = 0
  413.   cboValue.Text = gsNULL_STR
  414.   Height = 5520
  415.   Width = 7224
  416.   Left = (frmMDI.Width - Width) / 2
  417.   Top = 0
  418.   Exit Sub
  419. FLErr:
  420.   ShowError
  421.   Exit Sub
  422. End Sub
  423. Private Sub Form_Resize()
  424.   On Error Resume Next
  425.   If WindowState <> 1 Then
  426.     Me.Height = 5430
  427.     Me.Width = 7575
  428.   End If
  429. End Sub
  430. Private Sub cmdGetValues_Click()
  431.   On Error GoTo GVErr
  432.   Dim rec As Recordset
  433.   MsgBar "Getting Possible Values", True
  434.   SetHourglass
  435.   Set rec = gdbCurrentDB.OpenRecordset("select Distinct " & cboField & " from " & stSTF((cboField), 0))
  436.   Do While rec.EOF = False
  437.     If Len(Trim(rec(0))) > 0 Then
  438.       cboValue.AddItem rec(0).Value
  439.     End If
  440.     rec.MoveNext
  441.   Loop
  442.   rec.Close
  443.   cboValue.Text = cboValue.List(0)
  444.   cboValue.SetFocus
  445.   Screen.MousePointer = vbDefault
  446.   MsgBar gsNULL_STR, False
  447.   Exit Sub
  448. GVErr:
  449.   Screen.MousePointer = vbDefault
  450.   MsgBar gsNULL_STR, False
  451.   cboValue.Text = gsNULL_STR
  452.   Exit Sub
  453. End Sub
  454. Private Sub cmdJoin_Click()
  455.   Dim i As Integer
  456.   Dim c As Integer
  457.   For i = 0 To lstTables.ListCount - 1
  458.     If lstTables.Selected(i) = True Then
  459.       c = c + 1
  460.     End If
  461.   Next
  462.   If c < 2 Then
  463.     Beep
  464.     MsgBox "You Must Have at Least 2 Tables Selected!", 48
  465.   Else
  466.     MsgBar "Choose Joins", False
  467.     frmJoin.Show vbModal
  468.     MsgBar gsNULL_STR, False
  469.   End If
  470. End Sub
  471. Private Sub cmdOr_Click()
  472.   Dim nType As Integer
  473.   Dim sFieldName As String
  474.   Dim sTableName As String
  475.   If Len(cboField.Text) = 0 Then Exit Sub
  476.   sTableName = stSTF((cboField), 0)
  477.   sFieldName = stSTF((cboField), 1)
  478.   nType = gdbCurrentDB.TableDefs(StripBrackets(sTableName)).Fields(StripBrackets(sFieldName)).Type
  479.   If Len(txtCriteria.Text) > 0 Then
  480.     txtCriteria.Text = txtCriteria.Text & gsNewLine & " Or "
  481.   End If
  482.   If nType = dbText Or nType = dbMemo Or nType = dbDate Then
  483.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " '" & cboValue.Text & "'"
  484.   Else
  485.     txtCriteria.Text = txtCriteria.Text & cboField.Text & " " & cboOperator.Text & " " & cboValue.Text
  486.   End If
  487.   cboField.SetFocus
  488. End Sub
  489. Private Sub cmdRunQuery_Click()
  490.   On Error GoTo OKErr
  491.   Dim rec As Recordset
  492.   Dim fs As String
  493.   Dim ts As String
  494.   Dim i As Integer
  495.   Dim sWhere As String
  496.   Dim sWhere2 As String
  497.   Dim sNewWhere As String
  498.   Dim sTmp As String
  499.   Dim bMatchParen As Integer
  500.   Dim sQueryName As String
  501.   Dim qdfTmp As QueryDef
  502.   If lstShowFields.ListCount = 0 Then
  503.     MsgBox "No Query Entered!", vbExclamation
  504.     Exit Sub
  505.   End If
  506.   MsgBar "Building Query", True
  507.   If Len(txtCriteria.Text) > 0 Then
  508.     sWhere = "AND " & LTrim(txtCriteria.Text)
  509.     'strip gsNewLines
  510.     For i = 1 To Len(sWhere)
  511.       If Mid(sWhere, i, 1) = Chr(13) Then
  512.         sTmp = sTmp & " "
  513.       ElseIf Mid(sWhere, i, 1) = Chr(10) Then
  514.         'do nothing
  515.       Else
  516.         sTmp = sTmp + Mid(sWhere, i, 1)
  517.       End If
  518.     Next
  519.     sWhere = sTmp
  520.     sWhere = RTrim(sWhere)
  521.     'Add parens to sWhere
  522.      sWhere2 = sWhere
  523.      Do
  524.        sTmp = stGetToken(sWhere2, " ")
  525.        sTmp = sTmp & " "
  526.         If bMatchParen = False And UCase(sTmp) = "AND " Then
  527.          sNewWhere = sNewWhere + sTmp & "("
  528.          bMatchParen = True
  529.        ElseIf bMatchParen = True And UCase(sTmp) = "AND " Then
  530.          sNewWhere = sNewWhere & ") " & sTmp & "("
  531.          'bMatchParen = False
  532.        Else
  533.          If UCase(sTmp) = "OR" Or UCase(sTmp) = "IN " Or UCase(sTmp) = "LIKE" Then
  534.            sNewWhere = sNewWhere & " " & sTmp
  535.          Else
  536.            sNewWhere = sNewWhere + sTmp
  537.          End If
  538.        End If
  539.      Loop Until sWhere2 = gsNULL_STR
  540.      sWhere = sNewWhere & ")"
  541.     'Build DynaSet string:
  542.     'Peel off leading AND/OR
  543.     If Mid(sWhere, 2, 2) = "OR" Then
  544.       sWhere = Mid(sWhere, 5, Len(sWhere) - 5)
  545.     Else
  546.       sTmp = stGetToken(sWhere, " ")
  547.     End If
  548.     If Len(sWhere) > 0 Then
  549.       sWhere = " Where " & sWhere
  550.     End If
  551.   End If
  552.   'check for join condition
  553.   If lstJoinFields.ListCount > 0 Then
  554.     If Len(sWhere) = 0 Then
  555.       sWhere = sWhere & " Where "
  556.     Else
  557.       sWhere = sWhere & " And "
  558.     End If
  559.     For i = 0 To lstJoinFields.ListCount - 1
  560.       sWhere = sWhere + lstJoinFields.List(i) & " And "
  561.     Next
  562.     sWhere = Mid(sWhere, 1, Len(sWhere) - 5)
  563.   End If
  564.   'check for group by field
  565.   If cboGroupByField <> "(none)" Then
  566.     sWhere = sWhere & " Group By " & cboGroupByField
  567.   End If
  568.   'check for order by field
  569.   If cboOrderByField <> "(none)" Then
  570.     sWhere = sWhere & " Order By " & cboOrderByField
  571.     If optOrder(1).Value = True Then
  572.       sWhere = sWhere & " Desc "
  573.     End If
  574.   End If
  575.   'get show field names
  576.   For i% = 0 To lstShowFields.ListCount - 1
  577.     If lstShowFields.Selected(i%) Then
  578.       fs = fs + lstShowFields.List(i%) & ","
  579.     End If
  580.   Next
  581.   If Len(fs) = 0 Then
  582.     For i% = 0 To lstTables.ListCount - 1
  583.       If lstTables.Selected(i%) Then
  584.         fs = fs + AddBrackets((lstTables.List(i%))) & ".*,"
  585.       End If
  586.     Next
  587.     If Len(fs) = 0 Then
  588.       fs = "*"
  589.     Else
  590.       fs = Mid(fs, 1, Len(fs) - 1)     'take off the last ","
  591.     End If
  592.   Else
  593.     fs = Mid(fs, 1, Len(fs) - 1)
  594.   End If
  595.   'get table names
  596.   For i% = 0 To lstTables.ListCount - 1
  597.     If lstTables.Selected(i%) Then
  598.       ts = ts + AddBrackets((lstTables.List(i%))) & ","
  599.     End If
  600.   Next
  601.   ts = Mid(ts, 1, Len(ts) - 1)
  602.   gsDynaString = "Select "
  603.   'set Top N Value if present
  604.   If Len(txtTopNValue.Text) > 0 Then
  605.     gsDynaString = gsDynaString & " TOP " & txtTopNValue.Text & " "
  606.     If chkTopPercent.Value = 1 Then
  607.       gsDynaString = gsDynaString & " PERCENT "
  608.     End If
  609.   End If
  610.   gsDynaString = gsDynaString & fs & " From " & ts + sWhere
  611.   If mbShowSQL = False And mbCopySQL = False And mbSaveSQL = False Then
  612.     MsgBar "Running Query", True
  613.     gbFromSQL = True
  614.     'create a new recordset form
  615.     If frmMDI.optNoDataCtl = True Then
  616.       Dim frmNDC As New frmDynaSnap
  617.       frmNDC.Show
  618.     ElseIf frmMDI.optDataCtl.Value = True Then
  619.       Dim frmDC As New frmDataControl
  620.       frmDC.Show
  621.     Else
  622.       Dim frmGRID As New frmDataGrid
  623.       frmGRID.Show
  624.     End If
  625.   ElseIf mbShowSQL = True Then
  626.     MsgBar gsNULL_STR, False
  627.     MsgBox gsDynaString, 0, "SQL Query"
  628.   ElseIf mbCopySQL = True Then
  629.     frmSQL.txtSQLStatement.Text = gsDynaString
  630.   ElseIf mbSaveSQL = True Then
  631.     MsgBar gsNULL_STR, False
  632.     sQueryName = InputBox("Enter QueryDef Name:")
  633.     If Len(sQueryName) = 0 Then Exit Sub
  634.     'check for a dupe and exit if the user won't overwrite it
  635.     If DupeTableName(sQueryName) = True Then
  636.       Exit Sub
  637.     End If
  638.     'add the new querydef
  639.     Set qdfTmp = gdbCurrentDB.CreateQueryDef(sQueryName, gsDynaString)
  640.     RefreshTables frmTables.lstTables, True
  641.   End If
  642.   MsgBar gsNULL_STR, False
  643.   Exit Sub
  644. OKErr:
  645.   If Err = 364 Then Exit Sub   'catch unloaded form
  646.   ShowError
  647.   Exit Sub
  648. End Sub
  649. Private Sub cmdShowSQL_Click()
  650.   mbShowSQL = True
  651.   Call cmdRunQuery_Click
  652.   mbShowSQL = False
  653. End Sub
  654. Private Function stGetToken(rsLine As String, rsDelim As String) As String
  655.   On Error GoTo GetTokenError
  656.   Dim iOpenQuote As Integer
  657.   Dim iCloseQuote As Integer
  658.   Dim iDelim As Integer
  659.   Dim stToken As String
  660.   iOpenQuote = InStr(1, rsLine, """")
  661.   iDelim = InStr(1, rsLine, rsDelim)
  662.   If (iOpenQuote > 0) And (iOpenQuote < iDelim) Then
  663.     iCloseQuote = InStr(iOpenQuote + 1, rsLine, """")
  664.     iDelim = InStr(iCloseQuote + 1, rsLine, rsDelim)
  665.   End If
  666.   If (iDelim% <> 0) Then
  667.     stToken = LTrim(RTrim(Mid(rsLine, 1, iDelim - 1)))
  668.     rsLine = Mid(rsLine, iDelim + 1)
  669.   Else
  670.     stToken = LTrim(RTrim(Mid(rsLine, 1)))
  671.     rsLine = gsNULL_STR
  672.   End If
  673.   If (Len(stToken) > 0) Then
  674.     If (Mid(stToken, 1, 1) = """") Then
  675.       stToken = Mid(stToken, 2)
  676.     End If
  677.     If (Mid(stToken, Len(stToken), 1) = """") Then
  678.       stToken = Mid(stToken, 1, Len(stToken) - 1)
  679.     End If
  680.   End If
  681.   stGetToken = stToken
  682.   Exit Function
  683. GetTokenError:
  684.   Exit Function
  685. End Function
  686. 'function to split the table and the field from a tbl.fld pair
  687. Private Function stSTF(rsName As String, rnPart As Integer) As String
  688.   If InStr(InStr(1, rsName, ".") + 1, rsName, ".") > 1 Then
  689.     rsName = StripOwner(rsName)
  690.   End If
  691.   If rnPart = 0 Then
  692.     stSTF = Mid(rsName, 1, InStr(1, rsName, ".") - 1)
  693.   Else
  694.     stSTF = Mid(rsName, InStr(1, rsName, ".") + 1, Len(rsName))
  695.   End If
  696. End Function
  697.