Using VB with Access. I'm getting some information from one staff table and then do some calculations on the form and then save this data onto another table which is my payment. the problem is that it does save but the name changes from what its supposed to be.
I think it may be something to do with the primary key but i'm not 100% sure.
please take a look at this code at provide some solutions.
FORM LOAD
[CODE=vb]Option Explicit
Dim dbmyDB As Database
Dim rsPayment As Recordset
Dim rsStaff As Recordset
Private Sub Form_Load()
Set dbmyDB = OpenDatabase("E :\skol\A2 Computing\Speed y Pizza database.mdb")
Set rsStaff = dbmyDB.OpenReco rdset("Staff", dbOpenDynaset)
Set dbmyDB = OpenDatabase("E :\skol\A2 Computing\Speed y Pizza database.mdb")
Set rsPayment = dbmyDB.OpenReco rdset("Payment" , dbOpenDynaset)
If Not rsStaff.EOF Then rsStaff.MoveFir st
Do While Not rsStaff.EOF
lstRecord.AddIt em rsStaff!Firstna me & " " & rsStaff!Lastnam e & vbTab & rsStaff!StaffID & " " & rsPayment!Paysl ipno
lstRecord.ItemD ata(lstRecord.N ewIndex) = rsStaff!StaffID
rsStaff.MoveNex t
Loop
If Not rsPayment.EOF Then rsPayment.MoveF irst
Do While Not rsPayment.EOF
lstRecord.ItemD ata(lstRecord.N ewIndex) = rsPayment!Paysl ipno
rsPayment.MoveN ext
Loop
End Sub[/CODE]
LIST BOX
[CODE=vb]Private Sub lstRecord_Click ()
'
rsStaff.FindFir st "StaffID=" & (lstRecord.Item Data(lstRecord. ListIndex))
rsPayment.FindF irst "Payslipno= " & (lstRecord.Item Data(lstRecord. ListIndex))
txtStaffid.Text = rsStaff!StaffID 'Primary key on staff table & foreign key on Payment table
txtName.Text = rsStaff!Firstna me
txtSname.Text = rsStaff!Lastnam e
txtPayslipno.Te xt = rsPayment!Paysl ipno 'Primary key for Payment table
txtDate.Text = rsPayment!Date
txtNoofdayswork ed.Text = rsPayment!Noofd aysworked
cmbPayperhour.T ext = rsPayment!Paype rhour
txtHoursworked. Text = rsPayment!Hours worked
txtAftertax.Tex t = rsPayment!After tax
txtBonus.Text = rsPayment!Bonus
txtTotal.Text = rsPayment!Total payment
If rsStaff!Tax_ded uction Then
chkTax.Value = 1
Else
chkTax.Value = 0
End If
End Sub[/CODE]
Please could you help me
THANK U
I think it may be something to do with the primary key but i'm not 100% sure.
please take a look at this code at provide some solutions.
FORM LOAD
[CODE=vb]Option Explicit
Dim dbmyDB As Database
Dim rsPayment As Recordset
Dim rsStaff As Recordset
Private Sub Form_Load()
Set dbmyDB = OpenDatabase("E :\skol\A2 Computing\Speed y Pizza database.mdb")
Set rsStaff = dbmyDB.OpenReco rdset("Staff", dbOpenDynaset)
Set dbmyDB = OpenDatabase("E :\skol\A2 Computing\Speed y Pizza database.mdb")
Set rsPayment = dbmyDB.OpenReco rdset("Payment" , dbOpenDynaset)
If Not rsStaff.EOF Then rsStaff.MoveFir st
Do While Not rsStaff.EOF
lstRecord.AddIt em rsStaff!Firstna me & " " & rsStaff!Lastnam e & vbTab & rsStaff!StaffID & " " & rsPayment!Paysl ipno
lstRecord.ItemD ata(lstRecord.N ewIndex) = rsStaff!StaffID
rsStaff.MoveNex t
Loop
If Not rsPayment.EOF Then rsPayment.MoveF irst
Do While Not rsPayment.EOF
lstRecord.ItemD ata(lstRecord.N ewIndex) = rsPayment!Paysl ipno
rsPayment.MoveN ext
Loop
End Sub[/CODE]
LIST BOX
[CODE=vb]Private Sub lstRecord_Click ()
'
rsStaff.FindFir st "StaffID=" & (lstRecord.Item Data(lstRecord. ListIndex))
rsPayment.FindF irst "Payslipno= " & (lstRecord.Item Data(lstRecord. ListIndex))
txtStaffid.Text = rsStaff!StaffID 'Primary key on staff table & foreign key on Payment table
txtName.Text = rsStaff!Firstna me
txtSname.Text = rsStaff!Lastnam e
txtPayslipno.Te xt = rsPayment!Paysl ipno 'Primary key for Payment table
txtDate.Text = rsPayment!Date
txtNoofdayswork ed.Text = rsPayment!Noofd aysworked
cmbPayperhour.T ext = rsPayment!Paype rhour
txtHoursworked. Text = rsPayment!Hours worked
txtAftertax.Tex t = rsPayment!After tax
txtBonus.Text = rsPayment!Bonus
txtTotal.Text = rsPayment!Total payment
If rsStaff!Tax_ded uction Then
chkTax.Value = 1
Else
chkTax.Value = 0
End If
End Sub[/CODE]
Please could you help me
THANK U
Comment