home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Samples / VB_SMPL / VB_SMPL.ZIP / SEEKLST.EXE / SEEK_PUB.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-26  |  10.5 KB  |  333 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Table Object of Publishers Name from List box to Seek"
  4.    ClientHeight    =   5865
  5.    ClientLeft      =   1110
  6.    ClientTop       =   1020
  7.    ClientWidth     =   6375
  8.    Height          =   6270
  9.    Left            =   1050
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5865
  12.    ScaleWidth      =   6375
  13.    Top             =   675
  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 Pubid num selected from list box
  205. Dim db1 As database             '** database var
  206. Dim ds1 As dynaset              '** dynaset var
  207. Dim tbl1 As table               '** table var for seeking
  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 readonly list box(faster)
  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 for readonly list box(faster)
  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% = list1.ListIndex
  254.  Set tbl1 = db1.OpenTable("publishers")
  255.  tbl1.Index = "primarykey"
  256.  tbl1.Seek "=", a% + 1
  257. If tbl1.NoMatch 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$(tbl1("PubID")))
  267.  text2.Text = Trim$(" " & tbl1("Company Name"))
  268.  text3.Text = Trim$(" " & tbl1("telephone"))
  269.  text4.Text = Trim$(" " & tbl1("city"))
  270.  text5.Text = Trim$(" " & tbl1("state"))
  271.  text6.Text = Trim$(" " & tbl1("zip"))
  272.  text7.Text = Trim$(" " & tbl1("fax"))
  273.  text8.Text = Trim$(" " & tbl1("Address"))
  274. End If
  275.  tbl1.Close
  276.  db1.Close
  277.  text1.SetFocus
  278. End Sub
  279. Sub Text1_KeyPress (keyascii As Integer)
  280.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  281. End Sub
  282. Sub Text2_KeyPress (keyascii As Integer)
  283.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  284. End Sub
  285. Sub Text3_KeyPress (keyascii As Integer)
  286.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  287. End Sub
  288. Sub Text4_KeyPress (keyascii As Integer)
  289.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  290. End Sub
  291. Sub Text5_KeyPress (keyascii As Integer)
  292.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  293. End Sub
  294. Sub Text6_KeyPress (keyascii As Integer)
  295.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  296. End Sub
  297. Sub Text7_KeyPress (keyascii As Integer)
  298.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  299. End Sub
  300. Sub Text8_KeyPress (keyascii As Integer)
  301.  Call check_if_readonly(keyascii)    '** call procedure for readonly or not
  302. End Sub
  303. Sub update_record ()
  304.  Set db1 = OpenDatabase("c:\vb\biblio.mdb")   '** may need to change path
  305.  Set tbl1 = db1.OpenTable("publishers")
  306.  tbl1.Index = "primarykey"
  307.  tbl1.Seek "=", a% + 1                                 '** retain old record to update
  308. If tbl1.NoMatch Then
  309.  text1.Text = " "
  310.  text2.Text = " "
  311.  text3.Text = " "
  312.  text4.Text = " "
  313.  text5.Text = " "
  314.  text6.Text = " "
  315.  text7.Text = " "
  316.  text8.Text = " "
  317.  tbl1.Edit
  318.  tbl1("PubID") = Val(text1.Text)
  319.  tbl1("Company Name") = text2.Text
  320.  tbl1("telephone") = text3.Text
  321.  tbl1("city") = text4.Text
  322.  tbl1("state") = text5.Text
  323.  tbl1("zip") = text6.Text
  324.  tbl1("fax") = text7.Text
  325.  tbl1("Address") = text8.Text
  326.  tbl1.Update
  327. End If
  328.  tbl1.Close
  329.  db1.Close
  330.  command3.Visible = False
  331.  command4.Visible = False
  332. End Sub
  333.