Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    17

    Unanswered: Viewing database information in VB

    Hi, i'm new to VB and I need help with viewing my database through VB. I created a database using MS Access, and have connected it to VB using the VB data form wizard, but when I try to run the form it wont show the information stored in the fields of the database.

    Here is the code of the form: -
    -----------------------------------------------------
    Private Sub Form_Unload(Cancel As Integer)
    Screen.MousePointer = vbDefault
    End Sub

    Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
    'This is where you would put error handling code
    'If you want to ignore errors, comment out the next line
    'If you want to trap them, add code here to handle them
    MsgBox "Data error event hit err:" & Description
    End Sub

    Private Sub datPrimaryRS_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
    datPrimaryRS.Caption = "Record: " & CStr(datPrimaryRS.Recordset.AbsolutePosition)
    End Sub

    Private Sub datPrimaryRS_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 cmdAdd_Click()
    On Error GoTo AddErr
    datPrimaryRS.Recordset.AddNew

    Exit Sub
    AddErr:
    MsgBox Err.Description
    End Sub

    Private Sub cmdDelete_Click()
    On Error GoTo DeleteErr
    With datPrimaryRS.Recordset
    .Delete
    .MoveNext
    If .EOF Then .MoveLast
    End With
    Exit Sub
    DeleteErr:
    MsgBox Err.Description
    End Sub

    Private Sub cmdRefresh_Click()
    'This is only needed for multi user apps
    On Error GoTo RefreshErr
    datPrimaryRS.Refresh
    Exit Sub
    RefreshErr:
    MsgBox Err.Description
    End Sub

    Private Sub cmdUpdate_Click()
    On Error GoTo UpdateErr

    datPrimaryRS.Recordset.UpdateBatch adAffectAll
    Exit Sub
    UpdateErr:
    MsgBox Err.Description
    End Sub

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

    Could someone please tell me what i'm doing wrong, and how to view the information stored in the fields of my database.

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346

    Re: Viewing database information in VB

    Did you bind the textboxes and other controls on your form to your recordset (either through the properties window or through code as follows)?

    i.e.

    Set TextBox.DataSource = datPrimaryRS
    TextBox.DataField = "Field1"
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Apr 2004
    Posts
    17
    I was under the impression that the data form wizard did that automatically, if it doesn't then where abouts on my above coding would I put that piece of code you posted.

    I must stress that I am a beginer at all this, I'm trying to learn all of this from 'visual basic 6 for dummies'

    I've tried following the book word for word but I'm still stuck.

  4. #4
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    You are right it may already be done.

    Go into design mode in VB right-click on one of your textboxes and select properties check the property list for datasource and datafield, if they are filled out excellent if not you can put that code after you have created the recordset (I didn't see a load event in your code)
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  5. #5
    Join Date
    Apr 2004
    Posts
    17
    I have checked the properties of the text boxes and the datasource and datafield properties are both filled out, but it still wont show the data that i have in the fields of my database table.

  6. #6
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    This may be a long shot but did you try clicking on Move Next or Move Previous? You may be on the BOF or EOF record?
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •