home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SAMPLES / VISDATA / SQL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-10-16  |  6.0 KB  |  175 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSQL 
  3.    Caption         =   "SQL Statement"
  4.    ClientHeight    =   2880
  5.    ClientLeft      =   3690
  6.    ClientTop       =   1575
  7.    ClientWidth     =   5130
  8.    BeginProperty Font 
  9.       Name            =   "Tahoma"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   400
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    HelpContextID   =   2016144
  18.    Icon            =   "SQL.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    LockControls    =   -1  'True
  21.    MDIChild        =   -1  'True
  22.    ScaleHeight     =   2863.353
  23.    ScaleMode       =   0  'User
  24.    ScaleWidth      =   5147.588
  25.    ShowInTaskbar   =   0   'False
  26.    Begin VB.CommandButton cmdSaveQueryDef 
  27.       Caption         =   "&Save"
  28.       Height          =   375
  29.       Left            =   3375
  30.       MaskColor       =   &H00000000&
  31.       TabIndex        =   3
  32.       Top             =   30
  33.       Visible         =   0   'False
  34.       Width           =   1695
  35.    End
  36.    Begin VB.CommandButton cmdExecuteSQL 
  37.       Caption         =   "&Execute"
  38.       Default         =   -1  'True
  39.       Enabled         =   0   'False
  40.       Height          =   375
  41.       Left            =   15
  42.       MaskColor       =   &H00000000&
  43.       TabIndex        =   1
  44.       Top             =   30
  45.       Width           =   1575
  46.    End
  47.    Begin VB.CommandButton cmdClearSQL 
  48.       Caption         =   "&Clear"
  49.       Height          =   375
  50.       Left            =   1695
  51.       MaskColor       =   &H00000000&
  52.       TabIndex        =   2
  53.       Top             =   30
  54.       Width           =   1575
  55.    End
  56.    Begin VB.TextBox txtSQLStatement 
  57.       BackColor       =   &H00FFFFFF&
  58.       Height          =   2175
  59.       Left            =   15
  60.       MultiLine       =   -1  'True
  61.       ScrollBars      =   2  'Vertical
  62.       TabIndex        =   0
  63.       Top             =   435
  64.       Width           =   5055
  65.    End
  66. Attribute VB_Name = "frmSQL"
  67. Attribute VB_GlobalNameSpace = False
  68. Attribute VB_Creatable = False
  69. Attribute VB_TemplateDerived = False
  70. Attribute VB_PredeclaredId = True
  71. Attribute VB_Exposed = False
  72. Option Explicit
  73. '>>>>>>>>>>>>>>>>>>>>>>>>
  74. Const FORMCAPTION = "SQL Statement"
  75. Const BUTTON1 = "&Execute"
  76. Const BUTTON2 = "&Clear"
  77. Const BUTTON3 = "&Save"
  78. Const MSG1 = "Update"
  79. Const MSG2 = "Enter QueryDef Name:"
  80. Const MSG3 = "Is this a SQLPassThrough QueryDef?"
  81. Const MSG4 = "Enter Connect property value:"
  82. Const MSG5 = "Is the Query Row Returning?"
  83. '>>>>>>>>>>>>>>>>>>>>>>>>
  84. Private Sub cmdClearSQL_Click()
  85.   txtSQLStatement.Text = vbNullString
  86.   txtSQLStatement.SetFocus
  87. End Sub
  88. Private Sub cmdSaveQueryDef_Click()
  89.   On Error GoTo SQDErr
  90.   Dim sQueryName As String
  91.   Dim sTmp As String
  92.   Dim qdNew As QueryDef
  93.   If Not gnodDBNode Is Nothing Then
  94.     If gnodDBNode.Tag = QUERY_STR Then
  95.       'a querydef is selected so user may want to update it's SQL
  96.       If MsgBox(MSG1 & " '" & gnodDBNode.Text & "'?", vbYesNo + vbQuestion) = vbYes Then
  97.         'store the SQL from the SQL Window in the currently
  98.         'selected querydef
  99.         gdbCurrentDB.QueryDefs(gnodDBNode.Text).SQL = Me.txtSQLStatement.Text
  100.         Exit Sub
  101.       End If
  102.     End If
  103.   End If
  104.   'either there is no current querydef selected or the user
  105.   'didn't want to update the current one so we need
  106.   'to propmpt for a new name
  107.   sQueryName = InputBox(MSG2)
  108.   If Len(sQueryName) = 0 Then Exit Sub
  109.   'check for a dupe and exit if the user won't overwrite it
  110.   If DupeTableName(sQueryName) Then
  111.     Exit Sub
  112.   End If
  113.   'add the new querydef
  114.   Set qdNew = gdbCurrentDB.CreateQueryDef(sQueryName)
  115.   'prompt for passthrough querydef
  116.   If MsgBox(MSG3, vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
  117.     sTmp = InputBox(MSG4)
  118.     If Len(sTmp) > 0 Then
  119.       qdNew.Connect = sTmp
  120.       If MsgBox(MSG5, vbYesNo + vbQuestion) = vbNo Then
  121.         qdNew.ReturnsRecords = False
  122.       End If
  123.     End If
  124.   End If
  125.   qdNew.SQL = txtSQLStatement.Text
  126.   gdbCurrentDB.QueryDefs.Refresh
  127.   RefreshTables Nothing
  128.   Exit Sub
  129. SQDErr:
  130.   ShowError
  131. End Sub
  132. Private Sub Form_Unload(Cancel As Integer)
  133.   'only save the sql text if there are no carriage returns in it
  134.   'because they are not preserved in the INI file
  135. '  If InStr(frmSQL.txtSQLStatement.Text, Chr(13)) = 0 Then
  136.     SaveSetting APP_CATEGORY, App.Title, "SQLStatement", frmSQL.txtSQLStatement.Text
  137. '  End If
  138.   If frmSQL.WindowState = vbNormal Then
  139.     SaveSetting APP_CATEGORY, App.Title, "SQLWindowTop", frmSQL.Top
  140.     SaveSetting APP_CATEGORY, App.Title, "SQLWindowLeft", frmSQL.Left
  141.     SaveSetting APP_CATEGORY, App.Title, "SQLWindowWidth", frmSQL.Width
  142.     SaveSetting APP_CATEGORY, App.Title, "SQLWindowHeight", frmSQL.Height
  143.   End If
  144. End Sub
  145. Private Sub txtSQLStatement_Change()
  146.   cmdExecuteSQL.Enabled = Len(txtSQLStatement.Text) > 0
  147. End Sub
  148. Private Sub cmdExecuteSQL_Click()
  149.   If Len(txtSQLStatement.Text) = 0 Then Exit Sub
  150.   OpenQuery txtSQLStatement.Text, True
  151. End Sub
  152. Private Sub Form_Load()
  153.   Me.Caption = FORMCAPTION
  154.   cmdExecuteSQL.Caption = BUTTON1
  155.   cmdClearSQL.Caption = BUTTON2
  156.   cmdSaveQueryDef.Caption = BUTTON3
  157.   txtSQLStatement.Text = GetINIString("SQLStatement", vbNullString)
  158.   Me.Height = Val(GetINIString("SQLWindowHeight", "3000"))
  159.   Me.Width = Val(GetINIString("SQLWindowWidth", "5370"))
  160.   Me.Top = Val(GetINIString("SQLWindowTop", "0"))
  161.   Me.Left = Val(GetINIString("SQLWindowLeft", "3850"))
  162. End Sub
  163. Private Sub Form_Resize()
  164.   On Error Resume Next
  165.   If WindowState <> vbMinimized Then
  166.     txtSQLStatement.Width = Me.ScaleWidth - (txtSQLStatement.Left * 2)
  167.     txtSQLStatement.Height = Me.ScaleHeight - (txtSQLStatement.Top + 50)
  168.   End If
  169. End Sub
  170. Private Sub txtSQLStatement_DragDrop(Source As Control, x As Single, y As Single)
  171.   If Source = frmDatabase.tvDatabase Then
  172.     frmSQL.txtSQLStatement.Text = gdbCurrentDB.QueryDefs(gnodDBNode.Text).SQL
  173.   End If
  174. End Sub
  175.