|
-
Jun 28th, 2011, 06:00 AM
#1
Thread Starter
New Member
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?
-
Jun 28th, 2011, 06:03 AM
#2
Re: Displaying newly added records without exiting & rerun project.
How are you fetching the records? How are you displaying the records?
-
Jun 28th, 2011, 06:14 AM
#3
Thread Starter
New Member
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.
-
Jun 28th, 2011, 06:49 AM
#4
Fanatic Member
Re: Displaying newly added records without exiting & rerun project.
 Originally Posted by girl1329
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

-
Jun 28th, 2011, 07:02 AM
#5
Thread Starter
New Member
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 (- -")
-
Jun 28th, 2011, 07:15 PM
#6
Thread Starter
New Member
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.
-
Jun 29th, 2011, 02:52 AM
#7
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.
-
Jun 29th, 2011, 07:08 AM
#8
Thread Starter
New Member
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:
If txtCoachID.Text = "" Then MsgBox("Coach's staff no is not filled", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Data Retrieve Error") ElseIf CoachBindingSource.Find("coachStaffNo", txtCoachID.Text) <> -1 Then frmCoach.Show() frmCoach.txtCoachID.Text = Me.txtCoachID.Text If frmCoach.txtCoachPID.Text <> "" Then frmCoach.CoachBindingSource.Filter = "coachStaffNo ='" & CInt(frmCoach.txtCoachID.Text) & "'" frmCoach.PositionsBindingSource.Filter = "positionID = '" & CInt(frmCoach.txtCoachPID.Text) & "'" Else frmCoach.CoachBindingSource.Filter = "coachStaffNo ='" & CInt(frmCoach.txtCoachID.Text) & "'" End If Else 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") If response = MsgBoxResult.Yes Then frmCoach.Show() frmCoach.CoachBindingSource.AddNew() frmCoach.PositionsBindingSource.AddNew() End If End If End Sub
And here is the code for Save button in Coach form:
vb Code:
Private Sub TrainingListBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrainingListBindingNavigatorSaveItem.Click Try Me.Validate() Me.CoachBindingSource.EndEdit() Me.CoachTableAdapter.Update(Me.BLPDataSet.coach) Me.PositionsBindingSource.EndEdit() Me.PositionsTableAdapter.Update(Me.BLPDataSet.positions) documentChanged = False MsgBox("Data Saved!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Save Successful") Catch ex As Exception MsgBox("Data Update Failed", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Save Error") documentChanged = False End Try End If 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|