home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / acces2vb / frmdemom.frm < prev    next >
Text File  |  1994-03-02  |  20KB  |  676 lines

  1. VERSION 2.00
  2. Begin Form frmDemoMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "JET 2.0 VB3 Demo"
  5.    ClientHeight    =   6390
  6.    ClientLeft      =   1485
  7.    ClientTop       =   1635
  8.    ClientWidth     =   8970
  9.    Height          =   7110
  10.    Icon            =   FRMDEMOM.FRX:0000
  11.    Left            =   1410
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   6390
  14.    ScaleWidth      =   8970
  15.    Top             =   990
  16.    Width           =   9120
  17.    Begin CommandButton cmdExit 
  18.       Caption         =   "E&xit"
  19.       Height          =   375
  20.       Left            =   1980
  21.       TabIndex        =   11
  22.       Top             =   3420
  23.       Width           =   1035
  24.    End
  25.    Begin CommandButton cmdGo 
  26.       Caption         =   "&Go"
  27.       Height          =   375
  28.       Left            =   720
  29.       TabIndex        =   10
  30.       Top             =   3420
  31.       Width           =   1095
  32.    End
  33.    Begin TextBox txtDBLocation 
  34.       Height          =   315
  35.       Left            =   3780
  36.       TabIndex        =   12
  37.       Text            =   "C:\VB\BIBLIO.MDB"
  38.       Top             =   3480
  39.       Width           =   5055
  40.    End
  41.    Begin SSFrame Frame3D1 
  42.       Caption         =   "&Demo"
  43.       Height          =   3255
  44.       Left            =   120
  45.       TabIndex        =   14
  46.       Top             =   120
  47.       Width           =   3495
  48.       Begin SSOption o3dDemo 
  49.          Caption         =   "Other New Features"
  50.          Height          =   195
  51.          Index           =   20
  52.          Left            =   180
  53.          TabIndex        =   9
  54.          Top             =   2820
  55.          Width           =   2715
  56.       End
  57.       Begin SSOption o3dDemo 
  58.          Caption         =   "Correlated Subqueries"
  59.          Height          =   195
  60.          Index           =   3
  61.          Left            =   180
  62.          TabIndex        =   3
  63.          Top             =   1080
  64.          Width           =   2715
  65.       End
  66.       Begin SSOption o3dDemo 
  67.          Caption         =   "Top n Query"
  68.          Height          =   195
  69.          Index           =   2
  70.          Left            =   180
  71.          TabIndex        =   2
  72.          Top             =   840
  73.          Width           =   2715
  74.       End
  75.       Begin SSOption o3dDemo 
  76.          Caption         =   "DDL Create Index"
  77.          Height          =   195
  78.          Index           =   12
  79.          Left            =   180
  80.          TabIndex        =   6
  81.          Top             =   1980
  82.          Width           =   2895
  83.       End
  84.       Begin SSOption o3dDemo 
  85.          Caption         =   "Insert using Values clause"
  86.          Height          =   195
  87.          Index           =   14
  88.          Left            =   180
  89.          TabIndex        =   8
  90.          Top             =   2460
  91.          Width           =   2715
  92.       End
  93.       Begin SSOption o3dDemo 
  94.          Caption         =   "DDL Drop Table"
  95.          Height          =   195
  96.          Index           =   13
  97.          Left            =   180
  98.          TabIndex        =   7
  99.          Top             =   2220
  100.          Width           =   2715
  101.       End
  102.       Begin SSOption o3dDemo 
  103.          Caption         =   "DDL Alter Table - add column"
  104.          Height          =   195
  105.          Index           =   11
  106.          Left            =   180
  107.          TabIndex        =   5
  108.          Top             =   1740
  109.          Width           =   2895
  110.       End
  111.       Begin SSOption o3dDemo 
  112.          Caption         =   "DDL Create Table"
  113.          Height          =   195
  114.          Index           =   10
  115.          Left            =   180
  116.          TabIndex        =   4
  117.          Top             =   1500
  118.          Width           =   2715
  119.       End
  120.       Begin SSOption o3dDemo 
  121.          Caption         =   "Sub-Select Query"
  122.          Height          =   195
  123.          Index           =   1
  124.          Left            =   180
  125.          TabIndex        =   1
  126.          Top             =   600
  127.          Width           =   2715
  128.       End
  129.       Begin SSOption o3dDemo 
  130.          Caption         =   "UNION Query"
  131.          Height          =   195
  132.          Index           =   0
  133.          Left            =   180
  134.          TabIndex        =   0
  135.          Top             =   360
  136.          Width           =   2715
  137.       End
  138.    End
  139.    Begin Grid grdDemo 
  140.       Cols            =   10
  141.       FixedCols       =   0
  142.       Height          =   2415
  143.       Left            =   120
  144.       Rows            =   10
  145.       TabIndex        =   13
  146.       Top             =   3840
  147.       Width           =   8715
  148.    End
  149.    Begin Label Label2 
  150.       BackStyle       =   0  'Transparent
  151.       Caption         =   "SQL Command"
  152.       Height          =   255
  153.       Left            =   3900
  154.       TabIndex        =   17
  155.       Top             =   120
  156.       Width           =   1935
  157.    End
  158.    Begin Label lblExampleText 
  159.       BorderStyle     =   1  'Fixed Single
  160.       FontBold        =   0   'False
  161.       FontItalic      =   0   'False
  162.       FontName        =   "MS Sans Serif"
  163.       FontSize        =   9.75
  164.       FontStrikethru  =   0   'False
  165.       FontUnderline   =   0   'False
  166.       Height          =   2775
  167.       Left            =   3780
  168.       TabIndex        =   16
  169.       Top             =   300
  170.       Width           =   4935
  171.    End
  172.    Begin Label Label1 
  173.       BackStyle       =   0  'Transparent
  174.       Caption         =   "Sample DB Location"
  175.       Height          =   255
  176.       Left            =   3780
  177.       TabIndex        =   15
  178.       Top             =   3240
  179.       Width           =   2175
  180.    End
  181.    Begin Shape Shape1 
  182.       BackColor       =   &H00808080&
  183.       BackStyle       =   1  'Opaque
  184.       BorderStyle     =   0  'Transparent
  185.       Height          =   2775
  186.       Left            =   3840
  187.       Top             =   360
  188.       Width           =   4935
  189.    End
  190.    Begin Menu mnuFile 
  191.       Caption         =   "F&ile"
  192.       Begin Menu mnuFileCommands 
  193.          Caption         =   "&About"
  194.          Index           =   0
  195.       End
  196.       Begin Menu mnuFileCommands 
  197.          Caption         =   "E&xit"
  198.          Index           =   1
  199.       End
  200.    End
  201. End
  202. Option Explicit
  203.  
  204. Dim gDefaultDatabase As database
  205. Dim DBOpen_OK As Integer
  206.  
  207. Sub ClearGrid ()
  208.     Dim i As Integer
  209.     Dim j As Integer
  210.  
  211.     For i = 0 To 9
  212.         For j = 0 To 9
  213.             grdDemo.Col = i
  214.             grdDemo.Row = j
  215.             grdDemo.Text = ""
  216.         Next j
  217.     Next i
  218.  
  219. End Sub
  220.  
  221. Sub cmdExit_Click ()
  222.     Unload Me
  223.  
  224. End Sub
  225.  
  226. Sub cmdGo_Click ()
  227.     On Error Resume Next
  228.     
  229.     Dim ds As dynaset
  230.     
  231.     Dim i As Integer
  232.  
  233.     If Not DBOpen_OK Then
  234.         Set gDefaultDatabase = OpenDatabase(txtDBLocation.Text)
  235.         If Err <> 0 Then
  236.             MsgBox "Error Opening: " & txtDBLocation.Text
  237.             Exit Sub
  238.         End If
  239.         DBOpen_OK = True
  240.     End If
  241.  
  242.     ClearGrid
  243.     ResetGridWidths
  244.  
  245.     'UNION Query
  246.     If o3dDemo(0).Value = -1 Then
  247.         Me.MousePointer = 11
  248.  
  249.         grdDemo.ColWidth(1) = 2000
  250.         grdDemo.ColWidth(2) = 1500
  251.  
  252.         grdDemo.Row = 0
  253.         grdDemo.Col = 0
  254.         grdDemo.Text = "ID"
  255.  
  256.         grdDemo.Col = 1
  257.         grdDemo.Text = "Name"
  258.  
  259.         grdDemo.Col = 2
  260.         grdDemo.Text = "Type"
  261.  
  262.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  263.         If ds.RecordCount <> 0 Then
  264.             i = 1
  265.             Do Until ds.EOF
  266.                 grdDemo.Row = (i)
  267.  
  268.                 grdDemo.Col = 0
  269.                 grdDemo.Text = ds(0)
  270.  
  271.                 grdDemo.Col = 1
  272.                 grdDemo.Text = ds(1)
  273.  
  274.                 grdDemo.Col = 2
  275.                 grdDemo.Text = ds(2)
  276.                 
  277.                 ds.MoveNext
  278.                 i = i + 1
  279.                 If i > 9 Then
  280.                     Exit Do
  281.                 End If
  282.             Loop
  283.         End If
  284.         Me.MousePointer = 0
  285.     End If
  286.     
  287.     'Sub-Select Query
  288.     If o3dDemo(1).Value = -1 Then
  289.         Me.MousePointer = 11
  290.         
  291.         grdDemo.ColWidth(1) = 2000
  292.         grdDemo.ColWidth(2) = 2500
  293.  
  294.         grdDemo.Row = 0
  295.         grdDemo.Col = 0
  296.         grdDemo.Text = "Pub ID"
  297.  
  298.         grdDemo.Col = 1
  299.         grdDemo.Text = "Name"
  300.  
  301.         grdDemo.Col = 2
  302.         grdDemo.Text = "Company Name"
  303.  
  304.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  305.         If ds.RecordCount <> 0 Then
  306.             i = 1
  307.             Do Until ds.EOF
  308.                 grdDemo.Row = (i)
  309.  
  310.                 grdDemo.Col = 0
  311.                 grdDemo.Text = ds("PubID")
  312.  
  313.                 grdDemo.Col = 1
  314.                 grdDemo.Text = ds("Name")
  315.  
  316.                 grdDemo.Col = 2
  317.                 grdDemo.Text = ds("Company Name")
  318.                 
  319.                 ds.MoveNext
  320.                 i = i + 1
  321.                 If i > 9 Then
  322.                     Exit Do
  323.                 End If
  324.             Loop
  325.         End If
  326.         
  327.         Me.MousePointer = 0
  328.     End If
  329.  
  330.     
  331.     'Top n query
  332.     If o3dDemo(2).Value = -1 Then
  333.         Me.MousePointer = 11
  334.         
  335.         grdDemo.ColWidth(0) = 1400
  336.         grdDemo.ColWidth(1) = 2000
  337.         grdDemo.ColWidth(2) = 2000
  338.         grdDemo.ColWidth(3) = 4000
  339.  
  340.         grdDemo.Row = 0
  341.  
  342.         grdDemo.Col = 0
  343.         grdDemo.Text = "Year Published"
  344.  
  345.         grdDemo.Col = 1
  346.         grdDemo.Text = "Author"
  347.  
  348.         grdDemo.Col = 2
  349.         grdDemo.Text = "Name"
  350.  
  351.         grdDemo.Col = 3
  352.         grdDemo.Text = "Title"
  353.  
  354.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  355.         If ds.RecordCount <> 0 Then
  356.             i = 1
  357.             Do Until ds.EOF
  358.                 grdDemo.Row = (i)
  359.  
  360.                 grdDemo.Col = 0
  361.                 grdDemo.Text = ds("Year Published")
  362.  
  363.                 grdDemo.Col = 1
  364.                 grdDemo.Text = ds("Author")
  365.  
  366.                 grdDemo.Col = 2
  367.                 grdDemo.Text = ds("Name")
  368.  
  369.                 grdDemo.Col = 3
  370.                 grdDemo.Text = ds("Title")
  371.                 
  372.                 ds.MoveNext
  373.                 i = i + 1
  374.                 If i > 9 Then
  375.                     Exit Do
  376.                 End If
  377.             Loop
  378.         End If
  379.         Me.MousePointer = 0
  380.     
  381.     End If
  382.  
  383.     'Corellated sub-query
  384.     If o3dDemo(3).Value = -1 Then
  385.         
  386.         Me.MousePointer = 11
  387.  
  388.         grdDemo.ColWidth(0) = 800
  389.         grdDemo.ColWidth(1) = 1800
  390.         grdDemo.ColWidth(2) = 3500
  391.         
  392.         grdDemo.Row = 0
  393.  
  394.         grdDemo.Col = 0
  395.         grdDemo.Text = "Pub ID"
  396.  
  397.         grdDemo.Col = 1
  398.         grdDemo.Text = "Author"
  399.  
  400.         grdDemo.Col = 2
  401.         grdDemo.Text = "Title"
  402.  
  403.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  404.         If ds.RecordCount <> 0 Then
  405.             i = 1
  406.             Do Until ds.EOF
  407.                 grdDemo.Row = (i)
  408.  
  409.                 grdDemo.Col = 0
  410.                 grdDemo.Text = ds("PubID")
  411.  
  412.                 grdDemo.Col = 1
  413.                 grdDemo.Text = ds("Author")
  414.  
  415.                 grdDemo.Col = 2
  416.                 grdDemo.Text = ds("Title")
  417.                 
  418.                 ds.MoveNext
  419.                 i = i + 1
  420.                 If i > 9 Then
  421.                     Exit Do
  422.                 End If
  423.             Loop
  424.         End If
  425.         
  426.         Me.MousePointer = 0
  427.  
  428.     End If
  429.  
  430.  
  431.  
  432.     'Create Table
  433.     If o3dDemo(10).Value = -1 Then
  434.         If TableExists("My Test Table") Then
  435.             MsgBox "Table [My Test Table] already exists. Try doing a DROP TABLE command"
  436.             Exit Sub
  437.         End If
  438.         
  439.         On Error Resume Next
  440.         gDefaultDatabase.Execute lblExampleText
  441.         If Err <> 0 Then
  442.             MsgBox "error creating Test Table"
  443.         End If
  444.         
  445.         On Error GoTo 0
  446.     End If
  447.  
  448.     'Add column
  449.     If o3dDemo(11).Value = -1 Then
  450.         If Not TableExists("My Test Table") Then
  451.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  452.             Exit Sub
  453.         End If
  454.         
  455.         On Error Resume Next
  456.         
  457.         gDefaultDatabase.Execute lblExampleText
  458.         If Err <> 0 Then
  459.             MsgBox "Error adding column to My Test Table."
  460.         End If
  461.         
  462.         On Error GoTo 0
  463.     End If
  464.  
  465.     'Create Index
  466.     If o3dDemo(12).Value = -1 Then
  467.         If Not TableExists("My Test Table") Then
  468.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  469.             Exit Sub
  470.         End If
  471.         
  472.         On Error Resume Next
  473.         
  474.         gDefaultDatabase.Execute lblExampleText
  475.         If Err <> 0 Then
  476.             MsgBox "Error creating PrimaryKey index on My Test Table."
  477.         End If
  478.         
  479.         On Error GoTo 0
  480.     End If
  481.     
  482.     'Drop Table
  483.     If o3dDemo(13).Value = -1 Then
  484.         If Not TableExists("My Test Table") Then
  485.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  486.             Exit Sub
  487.         End If
  488.         
  489.         On Error Resume Next
  490.         
  491.         gDefaultDatabase.Execute lblExampleText
  492.         If Err <> 0 Then
  493.             MsgBox "Error dropping table My Test Table."
  494.         End If
  495.         
  496.         On Error GoTo 0
  497.     End If
  498.  
  499.  
  500.     'Insert Values...
  501.     If o3dDemo(14).Value = -1 Then
  502.         If Not TableExists("My Test Table") Then
  503.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  504.             Exit Sub
  505.         End If
  506.         
  507.         On Error Resume Next
  508.         
  509.         gDefaultDatabase.Execute lblExampleText
  510.         If Err <> 0 Then
  511.             MsgBox "Error inserting values into My Test Table."
  512.         End If
  513.         
  514.         On Error GoTo 0
  515.     End If
  516.  
  517.  
  518. End Sub
  519.  
  520. Sub Form_Load ()
  521.     
  522.     Dim i As Integer
  523.  
  524.     Me.Top = (screen.Height - Me.Height) / 2
  525.     Me.Left = (screen.Width - Me.Width) / 2
  526.  
  527.     ResetGridWidths
  528.     o3dDemo(0).Value = 1
  529.     
  530. End Sub
  531.  
  532. Sub Form_Unload (Cancel As Integer)
  533.     
  534.     If DBOpen_OK Then
  535.         gDefaultDatabase.Close
  536.     End If
  537.     
  538.     End
  539.  
  540. End Sub
  541.  
  542. Sub mnuFileCommands_Click (index As Integer)
  543.     Select Case index
  544.         
  545.         Case 0: frmAbout.Show 1
  546.         Case 1: Unload Me
  547.  
  548.     End Select
  549.  
  550. End Sub
  551.  
  552. Sub o3dDemo_Click (index As Integer, Value As Integer)
  553.     Dim strNewText As String
  554.     Dim crlf As String
  555.  
  556.     crlf = Chr$(13) & Chr$(10)
  557.  
  558.     Select Case index
  559.         Case 0' UNION
  560.             strNewText = "SELECT DISTINCTROW " & crlf
  561.             strNewText = strNewText & "Authors.Au_ID as IDNum , " & crlf
  562.             strNewText = strNewText & "Authors.Author as IDName, " & crlf
  563.             strNewText = strNewText & "'Author' as ColType " & crlf
  564.             strNewText = strNewText & "FROM Authors " & crlf
  565.             strNewText = strNewText & "UNION SELECT DISTINCTROW " & crlf
  566.             strNewText = strNewText & "Publishers.PubID, " & crlf
  567.             strNewText = strNewText & "Publishers.Name, " & crlf
  568.             strNewText = strNewText & "'Publisher' as ColType " & crlf
  569.             strNewText = strNewText & "FROM Publishers " & crlf
  570.             strNewText = strNewText & "ORDER BY IDName; "
  571.             
  572.         Case 1' Sub-Select Query
  573.             strNewText = "SELECT DISTINCTROW Publishers.* " & crlf
  574.             strNewText = strNewText & "FROM Publishers " & crlf
  575.             strNewText = strNewText & "where Publishers.PubID in " & crlf
  576.             strNewText = strNewText & "(SELECT DISTINCT Titles.PubID " & crlf
  577.             strNewText = strNewText & "FROM Titles " & crlf
  578.             strNewText = strNewText & "WHERE ((Titles.Title Like '*SQL*'))) " & crlf
  579.             strNewText = strNewText & "ORDER BY [Company Name]; "
  580.             
  581.         Case 2' Top n Query
  582.             strNewText = "SELECT DISTINCTROW TOP 5 " & crlf
  583.             strNewText = strNewText & "Titles.[Year Published], " & crlf
  584.             strNewText = strNewText & "Authors.Author, " & crlf
  585.             strNewText = strNewText & "Publishers.Name, " & crlf
  586.             strNewText = strNewText & "Titles.Title " & crlf
  587.             strNewText = strNewText & "FROM (Titles INNER JOIN Authors ON Titles.Au_ID = Authors.Au_ID) " & crlf
  588.             strNewText = strNewText & "INNER JOIN Publishers ON Titles.PubID = Publishers.PubID " & crlf
  589.             strNewText = strNewText & "ORDER BY Titles.[Year Published], Authors.Author; "
  590.         
  591.         Case 3' Corellated subqueries:
  592.             strNewText = "SELECT DISTINCTROW " & crlf
  593.             strNewText = strNewText & "A.PubID, Authors.Author, A.Title " & crlf
  594.             strNewText = strNewText & "FROM Titles as A " & crlf
  595.             strNewText = strNewText & "INNER JOIN Authors ON A.Au_ID = Authors.Au_ID " & crlf
  596.             strNewText = strNewText & "WHERE " & crlf
  597.             strNewText = strNewText & "(1 < (SELECT count(*) from Titles as B " & crlf
  598.             strNewText = strNewText & "where A.PubID = B.PubID)) " & crlf
  599.             strNewText = strNewText & "ORDER BY A.PubID, Authors.Author; "
  600.             
  601.         Case 10' DDL Create Table
  602.             strNewText = "CREATE TABLE [My Test Table] " & crlf
  603.             strNewText = strNewText & "([Last Name] text (20), " & crlf
  604.             strNewText = strNewText & "[First Name] text (20), " & crlf
  605.             strNewText = strNewText & "[Department] text (2), " & crlf
  606.             strNewText = strNewText & "[Date Added] DateTime) "
  607.  
  608.         Case 11 'DDL Alter Table - add column
  609.             strNewText = strNewText & "ALTER TABLE [My Test Table] " & crlf
  610.             strNewText = strNewText & "ADD COLUMN RecID COUNTER; "
  611.  
  612.         Case 12' DDL Create Index
  613.             strNewText = strNewText & "CREATE  INDEX 'PrimaryKey' " & crlf
  614.             strNewText = strNewText & "ON  [My Test Table] " & crlf
  615.             strNewText = strNewText & "(RecID) WITH PRIMARY; "
  616.  
  617.         Case 13' DDL Drop Table
  618.             strNewText = "DROP TABLE [My Test Table]"
  619.         
  620.         Case 14' Insert values...
  621.             strNewText = "INSERT INTO [My Test Table] " & crlf
  622.             strNewText = strNewText & "( [Last Name], " & crlf
  623.             strNewText = strNewText & "[First Name], " & crlf
  624.             strNewText = strNewText & "[Department], " & crlf
  625.             strNewText = strNewText & "[Date Added] ) " & crlf
  626.             strNewText = strNewText & "VALUES " & crlf
  627.             strNewText = strNewText & "('Smith', " & crlf
  628.             strNewText = strNewText & "'John', " & crlf
  629.             strNewText = strNewText & "'20', " & crlf
  630.             strNewText = strNewText & "#04/1/94#);"
  631.         
  632.         Case 20' other features
  633.             strNewText = "* Cascading updates and deletes " & crlf
  634.             strNewText = strNewText & "* Update non-joined fields on 'one' side of a join " & crlf
  635.             strNewText = strNewText & "* Fill in the blank rows of a LEFT JOIN " & crlf
  636.             strNewText = strNewText & "* Support for Paradox 4.x format"
  637.  
  638.  
  639.     End Select
  640.  
  641.     lblExampleText = strNewText
  642.  
  643. End Sub
  644.  
  645. Sub ResetGridWidths ()
  646.     Dim i As Integer
  647.  
  648.     For i = 0 To 9
  649.         grdDemo.ColWidth(i) = 835
  650.     Next i
  651.  
  652. End Sub
  653.  
  654. Function TableExists (tname As Variant) As Integer
  655.  
  656.     TableExists = False
  657.  
  658.     Dim ss As snapshot
  659.     Set ss = gDefaultDatabase.ListTables()
  660.     
  661.     If ss.RecordCount <> 0 Then
  662.         ss.MoveFirst
  663.         Do Until ss.EOF
  664.             'Debug.Print ss("Name")
  665.             If ss("Name") = tname Then
  666.                 TableExists = True
  667.                 Exit Do
  668.             End If
  669.             ss.MoveNext
  670.         Loop
  671.     End If
  672.  
  673.  
  674. End Function
  675.  
  676.