home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / record / recordnu.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1995-05-02  |  6.3 KB  |  238 lines

  1. VERSION 2.00
  2. Begin Form RecordNumberfrm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Record Numbers"
  5.    ClientHeight    =   4080
  6.    ClientLeft      =   1320
  7.    ClientTop       =   1830
  8.    ClientWidth     =   6285
  9.    Height          =   4485
  10.    Left            =   1260
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4080
  13.    ScaleWidth      =   6285
  14.    Top             =   1485
  15.    Width           =   6405
  16.    Begin CommandButton Command4 
  17.       Caption         =   "<"
  18.       Height          =   330
  19.       Left            =   1500
  20.       TabIndex        =   5
  21.       Top             =   1665
  22.       Width           =   480
  23.    End
  24.    Begin CommandButton Command3 
  25.       Caption         =   "<<"
  26.       Height          =   330
  27.       Left            =   960
  28.       TabIndex        =   4
  29.       Top             =   1665
  30.       Width           =   480
  31.    End
  32.    Begin CommandButton Command2 
  33.       Caption         =   ">>"
  34.       Height          =   330
  35.       Left            =   4590
  36.       TabIndex        =   3
  37.       Top             =   1680
  38.       Width           =   480
  39.    End
  40.    Begin Data Data1 
  41.       Connect         =   ""
  42.       DatabaseName    =   "C:\VB\BIBLIO.MDB"
  43.       Exclusive       =   0   'False
  44.       Height          =   270
  45.       Left            =   1650
  46.       Options         =   0
  47.       ReadOnly        =   0   'False
  48.       RecordSource    =   "Titles"
  49.       Top             =   2970
  50.       Width           =   2835
  51.    End
  52.    Begin TextBox Text1 
  53.       DataField       =   "Title"
  54.       DataSource      =   "Data1"
  55.       Height          =   345
  56.       Left            =   1155
  57.       TabIndex        =   1
  58.       Top             =   435
  59.       Width           =   3990
  60.    End
  61.    Begin CommandButton Command1 
  62.       Caption         =   ">"
  63.       Height          =   330
  64.       Left            =   4050
  65.       TabIndex        =   0
  66.       Top             =   1680
  67.       Width           =   480
  68.    End
  69.    Begin Shape Shape1 
  70.       Height          =   1140
  71.       Index           =   1
  72.       Left            =   510
  73.       Top             =   1185
  74.       Width           =   5505
  75.    End
  76.    Begin Shape Shape1 
  77.       Height          =   1140
  78.       Index           =   0
  79.       Left            =   510
  80.       Top             =   2490
  81.       Width           =   5505
  82.    End
  83.    Begin Label Label3 
  84.       BackStyle       =   0  'Transparent
  85.       Caption         =   "Field Name"
  86.       ForeColor       =   &H00800000&
  87.       Height          =   270
  88.       Left            =   1170
  89.       TabIndex        =   8
  90.       Top             =   165
  91.       Width           =   2520
  92.    End
  93.    Begin Label Label2 
  94.       Alignment       =   2  'Center
  95.       BackStyle       =   0  'Transparent
  96.       Caption         =   "Label with buttons"
  97.       ForeColor       =   &H00800000&
  98.       Height          =   225
  99.       Index           =   1
  100.       Left            =   1965
  101.       TabIndex        =   7
  102.       Top             =   1395
  103.       Width           =   2040
  104.    End
  105.    Begin Label Label2 
  106.       Alignment       =   2  'Center
  107.       BackStyle       =   0  'Transparent
  108.       Caption         =   "Data Control"
  109.       ForeColor       =   &H00800000&
  110.       Height          =   225
  111.       Index           =   0
  112.       Left            =   1995
  113.       TabIndex        =   6
  114.       Top             =   2715
  115.       Width           =   2040
  116.    End
  117.    Begin Label Label1 
  118.       BorderStyle     =   1  'Fixed Single
  119.       Height          =   285
  120.       Left            =   2070
  121.       TabIndex        =   2
  122.       Top             =   1695
  123.       Width           =   1875
  124.    End
  125. Option Explicit
  126. Dim TotRec As Long
  127. Dim CurrRec As Long
  128. Dim JustUsedFind As Integer        'flag for find function
  129. Sub Command1_Click ()
  130. On Error Resume Next
  131.    Data1.Recordset.MoveNext
  132. If Data1.Recordset.EOF Then
  133.    Data1.Recordset.MoveLast
  134.    MsgBox "This is the end of the database"
  135.    Exit Sub
  136. End If
  137. End Sub
  138. Sub Command2_Click ()
  139. On Error Resume Next
  140.    Data1.Recordset.MoveLast
  141. End Sub
  142. Sub Command3_Click ()
  143. On Error Resume Next
  144.    Data1.Recordset.MoveFirst
  145. End Sub
  146. Sub Command4_Click ()
  147. On Error Resume Next
  148.    Data1.Recordset.MovePrevious
  149. If Data1.Recordset.BOF Then
  150.    Data1.Recordset.MoveFirst
  151.    MsgBox "This is the beginning of the database"
  152.    Exit Sub
  153. End If
  154. End Sub
  155. Sub Data1_Reposition ()
  156.   Dim bm As String
  157.   Dim ds As dynaset
  158.   If JustUsedFind = True Then
  159.     Set ds = Data1.Recordset.Clone()
  160.     bm = Data1.Recordset.Bookmark
  161.     ds.MoveFirst
  162.     CurrRec = 1
  163.     While ds.Bookmark <> bm
  164.       CurrRec = CurrRec + 1
  165.       ds.MoveNext
  166.     Wend
  167.     JustUsedFind = False
  168.   End If
  169.   SetRecNum
  170. End Sub
  171. Sub Data1_Validate (Action As Integer, Save As Integer)
  172.   On Error GoTo ValErr
  173.   'first check for a move from an addnew or edit record
  174.   If Action < 5 Then
  175.     SetRecNum
  176.   End If
  177.   Select Case Action
  178.     Case 1          'First
  179.       CurrRec = 1
  180.     Case 2          'Previous
  181.       If CurrRec = 1 Then Beep
  182.       If CurrRec <> 1 Then CurrRec = CurrRec - 1
  183.     Case 3          'Next
  184.       If CurrRec = TotRec Then Beep
  185.       If CurrRec <> TotRec Then CurrRec = CurrRec + 1
  186.     Case 4          'Last
  187.       CurrRec = TotRec
  188.     Case 5          'AddNew
  189.       'do nothing
  190.     Case 6          'Update
  191.     Case 7          'Delete
  192.       TotRec = TotRec - 1
  193.       SetRecNum
  194.     Case 8
  195.       'set the flag for use in the reposition event
  196.       JustUsedFind = True
  197.     Case 9          'BookMark
  198.       'do nothing"
  199.     Case 10          'Close
  200.   End Select
  201.   GoTo ValEnd
  202. ValErr:
  203.   Resume ValEnd
  204. ValEnd:
  205. End Sub
  206. Sub Form_Load ()
  207. Dim ds2 As dynaset
  208. On Error GoTo LoadErr
  209.   Data1.Refresh
  210.   CurrRec = 1
  211.   Set ds2 = Data1.Recordset.Clone()
  212.   If ds2.BOF = False Then
  213.     ds2.MoveLast
  214.     TotRec = ds2.RecordCount
  215.   Else
  216.     TotRec = 0
  217.   End If
  218.   ds2.Close
  219.   SetRecNum
  220.   GoTo LoadEnd
  221. LoadErr:
  222.   Unload Me
  223.   Resume LoadEnd
  224. LoadEnd:
  225. End Sub
  226. Sub SetRecNum ()
  227. If Data1.EditMode <> 2 Then
  228.     If Data1.Recordset.BOF = True Then
  229.       Data1.Caption = "Record BOF of " & TotRec
  230.     ElseIf Data1.Recordset.EOF = True Then
  231.       Data1.Caption = "Record EOF of " & TotRec
  232.     Else
  233.       Data1.Caption = "Record " & CurrRec & " of " & TotRec
  234.       Label1.Caption = "Record " & CurrRec & " of " & TotRec
  235.     End If
  236.   End If
  237. End Sub
  238.