Add new to my listbox!!!!!!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • THEAF
    New Member
    • Mar 2007
    • 52

    #1

    Add new to my listbox!!!!!!!!!

    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
    Last edited by debasisdas; Feb 8 '08, 12:53 PM. Reason: added code=vb tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    In FormLoad, you are using lstRecord's ItemData.. in both the Loops..

    lstRecord.ItemD ata(lstRecord.N ewIndex) = rsStaff!StaffID

    lstRecord.ItemD ata(lstRecord.N ewIndex) = rsPayment!Paysl ipno

    So, your StaffID is overwritten by PaySlipNo..
    I guess, you need to use different listbox for payments..

    Regards
    Veena

    Comment

    Working...