Results 1 to 8 of 8

Thread: Displaying newly added records without exiting & rerun project.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Displaying newly added records without exiting & rerun project.

    Hi,

    I've created a database in Access 2007 and connected it to Visual Basic 2008.

    My database have tables Coachee and Coach. Details of Coachee are displayed in one form and there's a button that when clicked will show details of the Coach of that particular Coachee in a another form.

    If the Coach is not in database, user will be prompt to insert a new Coach record. Problem is, when saved, the newly inserted record will not be displayed and i have to exit and rerun the program, only then the record will be displayed.

    How can I display the newly inserted records without exiting?

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Displaying newly added records without exiting & rerun project.

    How are you fetching the records? How are you displaying the records?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Re: Displaying newly added records without exiting & rerun project.

    i have two tables in Access:

    coachee(coacheeID,name,position,coachID) -i only listed a few fields to simplify it
    coach(coachID,name,position)

    in VB, form Coachee displays coachee details and coach details are retrieved by clicking Coach Details button on the coachee form

    i'm using coachbindingsource.filter to retrieve and display coach's details.

  4. #4
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Displaying newly added records without exiting & rerun project.

    Quote Originally Posted by girl1329 View Post
    i have two tables in Access:

    coachee(coacheeID,name,position,coachID) -i only listed a few fields to simplify it
    coach(coachID,name,position)

    in VB, form Coachee displays coachee details and coach details are retrieved by clicking Coach Details button on the coachee form

    i'm using coachbindingsource.filter to retrieve and display coach's details.
    you have to use begintransaction while inserting records in access.
    can you show me the code using to insert records?
    Visual Studio.net 2010
    If this post is useful, rate it


  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Re: Displaying newly added records without exiting & rerun project.

    i'm a newbie in VB. i didnt have any begintransaction.

    to insert records i just place textboxes dragged from the datasource (eg Coach ID), set visible=false and code another visible textbox in the form to transfer value into the invisible textbox when textchanged.

    it's noobish, i know. but it works. haha. oh god this is embarassing (- -")

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Re: Displaying newly added records without exiting & rerun project.

    so now i know i have to use begintransaction to insert records into Access.

    i've searched for information and it seems that i have to implement Ole.DB and SQL in order for begintransaction to work. My question is, currently i didn't implement any Ole.DB or SQL codes to connect my Access database to Visual Basic.

    so, how? please help.

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Displaying newly added records without exiting & rerun project.

    You don't need to use begintransaction or any such thing. There is some other problem with your code.
    If you show us the code, we might be able to figure out for you.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Re: Displaying newly added records without exiting & rerun project.

    Below is the code for View Details button (in Coachee form) which displays the details of the Coachee's coach in another form. if the Coach's ID existed in database, it will straight away display Coach's details. if not, a messagebox will ask the user whether he wants to insert a new record for Coach

    vb Code:
    1. If txtCoachID.Text = "" Then
    2.             MsgBox("Coach's staff no is not filled", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Data Retrieve Error")
    3.         ElseIf CoachBindingSource.Find("coachStaffNo", txtCoachID.Text) <> -1 Then
    4.             frmCoach.Show()
    5.             frmCoach.txtCoachID.Text = Me.txtCoachID.Text
    6.             If frmCoach.txtCoachPID.Text <> "" Then
    7.                 frmCoach.CoachBindingSource.Filter = "coachStaffNo ='" & CInt(frmCoach.txtCoachID.Text) & "'"
    8.                 frmCoach.PositionsBindingSource.Filter = "positionID = '" & CInt(frmCoach.txtCoachPID.Text) & "'"
    9.             Else
    10.                 frmCoach.CoachBindingSource.Filter = "coachStaffNo ='" & CInt(frmCoach.txtCoachID.Text) & "'"
    11.             End If
    12.         Else
    13.             response = MsgBox("There's no record of Coach with staff no " & txtCoachID.Text & vbNewLine & "Add new coach record?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Add New Coach Record")
    14.             If response = MsgBoxResult.Yes Then
    15.                 frmCoach.Show()
    16.  
    17.                 frmCoach.CoachBindingSource.AddNew()
    18.                 frmCoach.PositionsBindingSource.AddNew()
    19.        End If
    20.         End If
    21.     End Sub


    And here is the code for Save button in Coach form:
    vb Code:
    1. Private Sub TrainingListBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrainingListBindingNavigatorSaveItem.Click
    2.  Try
    3.                 Me.Validate()
    4.                 Me.CoachBindingSource.EndEdit()
    5.                 Me.CoachTableAdapter.Update(Me.BLPDataSet.coach)
    6.                 Me.PositionsBindingSource.EndEdit()
    7.                 Me.PositionsTableAdapter.Update(Me.BLPDataSet.positions)
    8.  
    9.                 documentChanged = False
    10.                 MsgBox("Data Saved!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Save Successful")
    11.             Catch ex As Exception
    12.                 MsgBox("Data Update Failed", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Save Error")
    13.                 documentChanged = False
    14.             End Try
    15.         End If
    16.     End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width