home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / SQL_SMTS / SQL_PUB.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-06  |  10.6 KB  |  335 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Dynaset SQL Select on Publishers Name from List box "
  4.    ClientHeight    =   5865
  5.    ClientLeft      =   1560
  6.    ClientTop       =   1410
  7.    ClientWidth     =   6375
  8.    Height          =   6270
  9.    Left            =   1500
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5865
  12.    ScaleWidth      =   6375
  13.    Top             =   1065
  14.    Width           =   6495
  15.    Begin CommandButton Command4 
  16.       Caption         =   "Push to Not Save Changes"
  17.       Height          =   615
  18.       Left            =   120
  19.       TabIndex        =   21
  20.       Top             =   5040
  21.       Visible         =   0   'False
  22.       Width           =   2415
  23.    End
  24.    Begin CommandButton Command3 
  25.       Caption         =   "Push to Save Changes"
  26.       Height          =   615
  27.       Left            =   3840
  28.       TabIndex        =   11
  29.       Top             =   5040
  30.       Visible         =   0   'False
  31.       Width           =   2415
  32.    End
  33.    Begin TextBox Text8 
  34.       Height          =   375
  35.       Left            =   3840
  36.       TabIndex        =   2
  37.       Top             =   1320
  38.       Width           =   2295
  39.    End
  40.    Begin TextBox Text7 
  41.       Height          =   375
  42.       Left            =   4080
  43.       TabIndex        =   7
  44.       Top             =   2760
  45.       Width           =   2055
  46.    End
  47.    Begin TextBox Text6 
  48.       Height          =   375
  49.       Left            =   4920
  50.       TabIndex        =   5
  51.       Top             =   2040
  52.       Width           =   1215
  53.    End
  54.    Begin TextBox Text5 
  55.       Height          =   375
  56.       Left            =   3240
  57.       TabIndex        =   4
  58.       Top             =   2040
  59.       Width           =   975
  60.    End
  61.    Begin TextBox Text4 
  62.       Height          =   375
  63.       Left            =   720
  64.       TabIndex        =   3
  65.       Top             =   2040
  66.       Width           =   1575
  67.    End
  68.    Begin TextBox Text3 
  69.       Height          =   375
  70.       Left            =   1200
  71.       TabIndex        =   6
  72.       Top             =   2760
  73.       Width           =   1815
  74.    End
  75.    Begin TextBox Text2 
  76.       Height          =   375
  77.       Left            =   1920
  78.       TabIndex        =   8
  79.       Top             =   3480
  80.       Width           =   2295
  81.    End
  82.    Begin ListBox List1 
  83.       Height          =   615
  84.       Left            =   1800
  85.       Sorted          =   -1  'True
  86.       TabIndex        =   0
  87.       Top             =   480
  88.       Width           =   2775
  89.    End
  90.    Begin TextBox Text1 
  91.       Height          =   375
  92.       Left            =   2160
  93.       TabIndex        =   1
  94.       Top             =   1320
  95.       Width           =   735
  96.    End
  97.    Begin CommandButton Command2 
  98.       Caption         =   "Push to make Read/Write"
  99.       Height          =   495
  100.       Left            =   3840
  101.       TabIndex        =   10
  102.       Top             =   4200
  103.       Width           =   2415
  104.    End
  105.    Begin CommandButton Command1 
  106.       Caption         =   "Push to make ReadOnly"
  107.       Height          =   495
  108.       Left            =   120
  109.       TabIndex        =   9
  110.       Top             =   4200
  111.       Width           =   2415
  112.    End
  113.    Begin Label Label10 
  114.       Alignment       =   2  'Center
  115.       AutoSize        =   -1  'True
  116.       Caption         =   "Default is Read/Write"
  117.       FontBold        =   -1  'True
  118.       FontItalic      =   -1  'True
  119.       FontName        =   "MS Sans Serif"
  120.       FontSize        =   9.75
  121.       FontStrikethru  =   0   'False
  122.       FontUnderline   =   0   'False
  123.       Height          =   240
  124.       Left            =   1800
  125.       TabIndex        =   22
  126.       Top             =   0
  127.       Width           =   2355
  128.    End
  129.    Begin Label Label9 
  130.       Caption         =   "Address:"
  131.       Height          =   255
  132.       Left            =   3000
  133.       TabIndex        =   20
  134.       Top             =   1320
  135.       Width           =   735
  136.    End
  137.    Begin Label Label8 
  138.       Caption         =   "Fax:"
  139.       Height          =   255
  140.       Left            =   3480
  141.       TabIndex        =   19
  142.       Top             =   2760
  143.       Width           =   495
  144.    End
  145.    Begin Label Label7 
  146.       Caption         =   "Zip:"
  147.       Height          =   255
  148.       Left            =   4440
  149.       TabIndex        =   18
  150.       Top             =   2040
  151.       Width           =   375
  152.    End
  153.    Begin Label Label6 
  154.       Caption         =   "State:"
  155.       Height          =   255
  156.       Left            =   2520
  157.       TabIndex        =   17
  158.       Top             =   2040
  159.       Width           =   615
  160.    End
  161.    Begin Label Label5 
  162.       Caption         =   "City:"
  163.       Height          =   255
  164.       Left            =   120
  165.       TabIndex        =   16
  166.       Top             =   2040
  167.       Width           =   495
  168.    End
  169.    Begin Label Label4 
  170.       Caption         =   "Company Name:"
  171.       Height          =   255
  172.       Left            =   120
  173.       TabIndex        =   15
  174.       Top             =   3600
  175.       Width           =   1455
  176.    End
  177.    Begin Label Label3 
  178.       Caption         =   "Telephone:"
  179.       Height          =   255
  180.       Left            =   120
  181.       TabIndex        =   14
  182.       Top             =   2760
  183.       Width           =   975
  184.    End
  185.    Begin Label Label2 
  186.       Caption         =   "Select a Publisher's Name from the List ---->"
  187.       Height          =   735
  188.       Left            =   120
  189.       TabIndex        =   13
  190.       Top             =   360
  191.       Width           =   1575
  192.    End
  193.    Begin Label Label1 
  194.       Caption         =   "Publisher Identification:"
  195.       Height          =   255
  196.       Left            =   120
  197.       TabIndex        =   12
  198.       Top             =   1320
  199.       Width           =   2055
  200.    End
  201. Option Explicit
  202. Dim readonly_flag%              '** readonly flag var
  203. Dim idx%                        '** index var for combo boxes
  204. Dim a$                          '** holds the string selected from list box
  205. Dim num_recs%                   '** holds the number of records found
  206. Dim db1 As database             '** database var
  207. Dim ds1 As dynaset              '** dynaset var
  208. Sub check_if_readonly (keyascii As Integer)
  209.  If keyascii > 0 And readonly_flag% = 1 Then     '** if they press any key and readonly_flag% = 1 then
  210.   keyascii = 0                                   '** turn keystroke off
  211.  Else
  212.   command3.Visible = True
  213.   command4.Visible = True
  214.  End If
  215. End Sub
  216. Sub Command1_Click ()
  217.  readonly_flag% = 1          '*** set readonly_flag% to 1 to makde text boxes readonly
  218.  label10.Caption = "ReadOnly record"
  219. End Sub
  220. Sub Command2_Click ()
  221.  readonly_flag% = 0          '*** set readonly_flag% to 0 to make text boxes read/write
  222.  label10.Caption = "Read/Write record"
  223. End Sub
  224. Sub Command3_Click ()
  225.  label10.Caption = "Changes made to the record, select another record"
  226.  Call update_record
  227. End Sub
  228. Sub Command4_Click ()
  229.  list1.SetFocus
  230.  label10.Caption = "No Changes made to the record, re-select same record"
  231.  command3.Visible = False
  232.  command4.Visible = False
  233.  label2.Caption = "Select another Publisher's Name from the List ---->"
  234. End Sub
  235. Sub Form_Load ()
  236.  readonly_flag% = 0        '** set default to read/write
  237.  Set db1 = OpenDatabase("c:\vb\biblio.mdb", False, True)      '** may need to change path, opened for readonly for list box(faster, list box readonly anyway)
  238.  Set ds1 = db1.CreateDynaset("select name from publishers")   '** bring in all(*) record in the authors table
  239.  Do While ds1.EOF = False
  240.   list1.AddItem " " & ds1("name")   '** add publisher names, if null add a space
  241.   ds1.MoveNext
  242.  Loop
  243.  ds1.Close
  244.  db1.Close
  245. End Sub
  246. Sub List1_Click ()
  247. If readonly_flag% = 1 Then
  248.  label10.Caption = "ReadOnly record"
  249.  Set db1 = OpenDatabase("c:\vb\biblio.mdb", False, True)     '** may need to change path, opened for readonly
  250.  label10.Caption = "Read/Write record"
  251.  Set db1 = OpenDatabase("c:\vb\biblio.mdb")      '** may need to change path, opened for read\write
  252. End If
  253.  a$ = Trim$(list1.List(list1.ListIndex))
  254.  Set ds1 = db1.CreateDynaset("select * from publishers where name = '" & a$ & "'")  '** sql statement that contains var to search on
  255.  ds1.MoveLast
  256.  num_recs% = ds1.RecordCount
  257. If num_recs% = 0 Then
  258.  text1.Text = " "
  259.  text2.Text = " "
  260.  text3.Text = " "
  261.  text4.Text = " "
  262.  text5.Text = " "
  263.  text6.Text = " "
  264.  text7.Text = " "
  265.  text8.Text = " "
  266.  text1.Text = Trim$(Str$(ds1("PubID")))
  267.  text2.Text = Trim$(" " & ds1("Company Name"))
  268.  text3.Text = Trim$(" " & ds1("telephone"))
  269.  text4.Text = Trim$(" " & ds1("city"))
  270.  text5.Text = Trim$(" " & ds1("state"))
  271.  text6.Text = Trim$(" " & ds1("zip"))
  272.  text7.Text = Trim$(" " & ds1("fax"))
  273.  text8.Text = Trim$(" " & ds1("Address"))
  274. End If
  275.   num_recs% = 0
  276.  ds1.Close
  277.  db1.Close
  278.  text1.SetFocus
  279. End Sub
  280. Sub Text1_KeyPress (keyascii As Integer)
  281.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  282. End Sub
  283. Sub Text2_KeyPress (keyascii As Integer)
  284.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  285. End Sub
  286. Sub Text3_KeyPress (keyascii As Integer)
  287.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  288. End Sub
  289. Sub Text4_KeyPress (keyascii As Integer)
  290.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  291. End Sub
  292. Sub Text5_KeyPress (keyascii As Integer)
  293.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  294. End Sub
  295. Sub Text6_KeyPress (keyascii As Integer)
  296.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  297. End Sub
  298. Sub Text7_KeyPress (keyascii As Integer)
  299.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  300. End Sub
  301. Sub Text8_KeyPress (keyascii As Integer)
  302.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  303. End Sub
  304. Sub update_record ()
  305.  Set db1 = OpenDatabase("c:\vb\biblio.mdb")   '** may need to change path
  306.  Set ds1 = db1.CreateDynaset("select * from publishers where name = '" & a$ & "'")
  307.  ds1.MoveLast
  308.  num_recs% = ds1.RecordCount
  309. If num_recs% = 0 Then
  310.  text1.Text = " "
  311.  text2.Text = " "
  312.  text3.Text = " "
  313.  text4.Text = " "
  314.  text5.Text = " "
  315.  text6.Text = " "
  316.  text7.Text = " "
  317.  text8.Text = " "
  318.  ds1.Edit
  319.  ds1("PubID") = Val(text1.Text)
  320.  ds1("Company Name") = text2.Text
  321.  ds1("telephone") = text3.Text
  322.  ds1("city") = text4.Text
  323.  ds1("state") = text5.Text
  324.  ds1("zip") = text6.Text
  325.  ds1("fax") = text7.Text
  326.  ds1("Address") = text8.Text
  327.  ds1.Update
  328. End If
  329.   num_recs% = 0
  330.  ds1.Close
  331.  db1.Close
  332.  command3.Visible = False
  333.  command4.Visible = False
  334. End Sub
  335.