Application developed with Visual Basic, Part 2.


The frmMain.frm, Book.frm and Module.bas files created by Wizard Application :

 

  1. The frmMain.frm file :

    1. The design.

      TestVB0
      ..... File .. Data
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .

      .


    2. The View Code.

       

      Private Sub Form_Load()
      Me.Left = GetSetting(App.Title
      , "Settings", "MainLeft", 1000)
      Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
      Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
      Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub Form_Unload(Cancel
      As Integer)
      Dim i As Integer


      'close all sub forms
      For i = Forms.Count - 1 To 1 Step -1
      Unload Forms(i)
      Next
      If Me.WindowState <> vbMinimized Then
      SaveSetting App.Title, "Settings", "MainLeft", Me.Left
      SaveSetting App.Title, "Settings", "MainTop", Me.Top
      SaveSetting App.Title, "Settings", "MainWidth", Me.Width
      SaveSetting App.Title, "Settings", "MainHeight", Me.Height
      End If
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub mnuDataBook_Click()
      Dim f As New Book
      f.Show
      End Sub

      ----------------------------------------------------------------------------------------------------------------------
      Private Sub mnuFileExit_Click()
      'unload the form
      Unload Me

      End Sub
  2. The Book.frm file :

    1. The design.

      BibleTable


    2. The View Code.

       
      Dim WithEvents adoPrimaryRS As Recordset
      Dim mbChangedByCode As Boolean
      Dim mvBookMark As Variant
      Dim mbEditFlag As Boolean
      Dim mbAddNewFlag As Boolean
      Dim mbDataChanged As Boolean

      Dim strdatasource As String
      ----------------------------------------------------------------------------------------------------------------------
      Private Sub Form_Load()

      'Value of strdatasource at current directory
      strdatasource = App.Path + "\res\KJV.mdb"

      Dim db As Connection
      Set db = New Connection
      db.CursorLocation = adUseClient
      db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & strdatasource

      Set adoPrimaryRS = New Recordset
      adoPrimaryRS.Open "select Book,BookTitle,Chapter,TextData,Verse from BibleTable", db, adOpenStatic, adLockOptimistic

      Dim oText As TextBox
      'Bind the text boxes to the data provider
      For Each oText In Me.txtFields
      Set oText.DataSource = adoPrimaryRS
      Next

      mbDataChanged = False
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub Form_Resize()
      On Error Resume Next
      lblStatus.Width = Me.Width - 1500
      cmdNext.Left = lblStatus.Width + 700
      cmdLast.Left = cmdNext.Left + 340
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub Form_KeyDown(KeyCode
      As Integer, Shift As Integer)
      If mbEditFlag Or mbAddNewFlag Then Exit Sub

      Select Case KeyCode
      Case vbKeyEscape
      cmdClose_Click
      Case vbKeyEnd
      cmdLast_Click
      Case vbKeyHome
      cmdFirst_Click
      Case vbKeyUp, vbKeyPageUp
      If Shift = vbCtrlMask Then
      cmdFirst_Click
      Else
      cmdPrevious_Click
      End If
      Case vbKeyDown, vbKeyPageDown
      If Shift = vbCtrlMask Then
      cmdLast_Click
      Else
      cmdNext_Click
      End If
      End Select
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub Form_Unload(Cancel As Integer)
      Screen.MousePointer = vbDefault
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub adoPrimaryRS_MoveComplete(ByVal
      adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
      'This will display the current record position for this recordset
      lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub adoPrimaryRS_WillChangeRecord(ByVal
      adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
      'This is where you put validation code
      'This event gets called when the following actions occur
      Dim bCancel As Boolean

      Select Case adReason
      Case adRsnAddNew
      Case adRsnClose
      Case adRsnDelete
      Case adRsnFirstChange
      Case adRsnMove
      Case adRsnRequery
      Case adRsnResynch
      Case adRsnUndoAddNew
      Case adRsnUndoDelete
      Case adRsnUndoUpdate
      Case adRsnUpdate
      End Select

      If bCancel Then adStatus = adStatusCancel
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub cmdClose_Click()
      Unload Me
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub cmdFirst_Click()
      On Error GoTo GoFirstError

      adoPrimaryRS.MoveFirst
      mbDataChanged = False

      Exit Sub

      GoFirstError:
      MsgBox Err.Description
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub cmdLast_Click()
      On Error GoTo GoLastError

      adoPrimaryRS.MoveLast
      mbDataChanged = False

      Exit Sub

      GoLastError:
      MsgBox Err.Description
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub cmdNext_Click()
      On Error GoTo GoNextError

      If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
      If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
      Beep
      'moved off the end so go back
      adoPrimaryRS.MoveLast
      End If
      'show the current record
      mbDataChanged = False

      Exit Sub
      GoNextError:
      MsgBox Err.Description
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub cmdPrevious_Click()
      On Error GoTo GoPrevError

      If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious
      If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
      Beep
      'moved off the end so go back
      adoPrimaryRS.MoveFirst
      End If
      'show the current record
      mbDataChanged = False

      Exit Sub

      GoPrevError:
      MsgBox Err.Description
      End Sub

      -----------------------------------------------------------------------------------------------------------------------
      Private Sub SetButtons(bVal As Boolean)
      cmdClose.Visible = bVal
      cmdNext.Enabled = bVal
      cmdFirst.Enabled = bVal
      cmdLast.Enabled = bVal
      cmdPrevious.Enabled = bVal
      End Sub
  3. The Module1.bas file View Code :

    Public fMainForm As frmMain

    -----------------------------------------------------------------------------------------------------------------------
    Sub Main()
    Set fMainForm = New frmMain
    fMainForm.Show
    End Sub

Previous
Home 2 Home
Next