Step 1:

Application developed with Visual Basic, Part 1.


1st Step, the beginning ...

  1. Create the folder Test in the C: drive, C:\Test.
  2. Create the folder Test VB0 in the folder Test, C:\Test\Test VB0.
  3. Create the folder res in the folder Test VB0, C:\Test\Test VB0\res.
  4. From the  ...\Visual_Basic\VB App\res folder,  copy the file - KJV.mdb to the folder C:\Test\Test VB0\res and remove the read-only attribute of the file C:\Test\Test VB0\res\KJV.mdb - (if exist).


2nd Step, create the wizard Application .

Microsoft Visual Basic Application Wizard: Programmatically, a Wizard is a form which contains a variable number of frames (or "steps"), each of which comprises a step to completing a Wizard’s task.

The Wizard steps ...: 

First, run the Microsoft Visual Basic  6

  1. From the File menu, choose New Project.
    The New Project dialog box appears, select the VB Application Wizard icon and then click OK.

  2. In the Application Wizard - Introduction dialog box:
  3. Click Next.

  4. In the Application Wizard - Interface Type dialog box:
  5. Select Single Document Interface (SDI).
  6. In the 'What name do you want for the application' box, type TestVB0.
  7. Click Next.

  8. In the Application Wizard - Menus dialog box:
  9. Remove the 'Edit, View, Window and Help' Menus. (clear the check boxes)
  10. From File Menu, remove the Sub Menu items - New, Open, Close, Save, Save As, Save All, Properties, Page setup, Print Preview, Print, Send and MRUList. (clear the check boxes)
  11. Click Next.

  12. In the Applicaction Wizard - Customize Toolbar dialog box:
  13. Remove all Toolbar items.
  14. Click Next.

  15. In the Applicaction Wizard - Resource dialog box:
  16. Select No. (Would you like to use a Resource file ...)
  17. Click Next.

  18. In the Application Wizard - Internet Connectivity dialog box:
  19. Select No. (Do you want your user to be able to access the Internet ...)
  20. Click Next.

  21. In the Application Wizard - Standard Forms dialog box:
  22. Click Next.

  23. In the Application Wizard - Data Access Forms dialog box:
  24. Click Create New Form.

    Note :
    The Data Form Wizard dialog box appears ...

  25. In the Data Form Wizard - Introduction dialog box:
  26. Click Next.

  27. In the Data Form Wizard - Database Type dialog box:
  28. Select Access. (Database type)
  29. Cick Next.

  30. In the Data Form Wizard - Database dialog box:
  31. Click Browse, the Access Database dialog box appears, locate and select the Microsoft Access database file - KJV.mdb in the folder c:\Test\Test VB0\res and then click Open.

    Note:
    In the Database Name box displays 'C:\Test\Test VB0\res\KJV.mdb'.
  32. Click Next.

  33. In the Data Form Wizard - Form dialog box:
  34. In the 'What name do you want for the form?' box, type Book.
  35. From the Form Layout list, select Single Record.
  36. From Binding Type, select ADO Code.
  37. Click Next.

  38. In the Data Form Wizard - Record Source dialog box:
  39. From the Record Source Combo Box, select the BibleTable table.
  40. From the Available Fields list, move by order all fields (Book, BookTitle, Chapter, TextData, Verse) to the Selected Fields list.
  41. Click Next.

  42. In the Data Form Wizard -Control Selection dialog box:
  43. Select or check only Close Button. - (Uncheck other check boxes)
  44. Click Next.

  45. In the Data Form Wizard -Finished! dialog box:
  46. Click Finish.

    Note:
    The Data Form Wizard dialog box appears.

  47. In the Data Form Wizard dialog box:
  48. Click No. (Create another Data Form?)

    Note:
    If the Source Code Control - (Add this project to SourceSafe) dialog box appears, click No.

  49. In the Applicaction Wizard - Data Access Forms dialog box:
  50. Click Finish.
  51. The Application Created dialog box appears, click OK.

  52. The application has been created.

  53. From the File menu, choose Save Project, the Save File As dialog box appears, locate and select the folder
    Test VB0 (c:\Test\Test VB0), and then click Save - (Book).
    Repeat this operation to save all files: frmMain, Module1 and TestVB0.

    Note:
    if
    the Source Code Control dialog box appears, click No.

    List of files created - (Working with Projects):
    File Description
    Book.frm Form demonstrating database algorithms.
    Book.frx Binary data file for the BOOK.FRM file.
    femMain.frm The main form for the sample application.
    Module1.bas Module containing shared code.
    TestVB0.vbp Project file for this application.


    Note
    :
    Book.frx - Binary data file save pictures in cmdLast, cmdNext, cmdPrevious, cmdFirst buttons.
    Some controls have properties that have binary data as their values, such as the Picture property of picture box and image controls or certain properties of custom controls. Visual Basic saves all binary data for a form in a binary data file separate from the form.
    Visual Basic saves the binary data file in the same directory as the form. The binary data file has the same file name as the form, but it has an .frx filename extension. Visual Basic reads the binary data file when loading the form.

  54. For more flexibility, use the path property of the App object to set the current path.
    Add the folowing text Code to the Book.frm View Code:
    'Type of the strdatasource
    Dim strdatasource As String
    ...................
    'Value of the strdatasource
    strdatasource = App.Path + "\res\KJV.mdb"
    ........................
    db1.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & strdatasource

    Note:
    The App object is a global object determines or specifies information about the application's title, version information, the path and name of its executable file and Help files, and whether or not a previous instance of the application is running.

    the Path property specifies the path of the project .VBP file when running the application from the development environment. Use this property when building an application's file-browsing and manipulation capabilities.

    Book.frm View Code after modification. Examine these changes:
    -
    The new text Code to be add is red.
    -
    The text Code to be remove is navy and Strikethrough effects.

    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
    'Type of the strdatasource
    Dim strdatasource As String
    -----------------------------------------------------------------------------------------------------------------------
    Private Sub Form_Load()

    'Value of the 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=C:\Test\Test VB0\res\KJV.mdb;"
    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


  55. To save this application; From File menu, choose and click Save Project.
  56. To run it; From Run menu, choose and click Start.

Home 1 Home
Next