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? :(
Re: Displaying newly added records without exiting & rerun project.
How are you fetching the records? How are you displaying the records?
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.
Re: Displaying newly added records without exiting & rerun project.
Quote:
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?
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 (- -")
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.
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.
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