Using a list box

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

    Using a list box

    OK.
    Im using Access and VB. I have data on two tables in access that I want to show on vb. 1 text box will show 1 data from 1table and same with the other table. i've opened both tables on vb using the recordset and the if not...EOF Then...MoveNext on the form load.
    i'v put the code behind the listbox to show the data form the seperate tables in the textboxes but it still won't work. Could anyone please tell me what in missing. Please give all the solutions you have.

    THANK YOU 4 ALL ANSWERS
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Originally posted by THEAF
    OK.
    i'v put the code behind the listbox to show the data form the seperate tables in the textboxes but it still won't work. Could anyone please tell me what in missing. Please give all the solutions you have.

    THANK YOU 4 ALL ANSWERS
    I have all the solutions for you ,but can you kindly clarify this i'v put the code behind the listbox to show the data form the seperate tables in the textboxes

    if u can post it clearly then it will be easier to understand and solve your problem.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Ignore me - just registering an interest in this thread.

      Comment

      • THEAF
        New Member
        • Mar 2007
        • 52

        #4
        OK. What I meant was...
        I'm doing a school project. I'm making a system software for an internet cafe. For this I'm using Visual basic and Microsoft Access. I'm using this code:

        [CODE=vb]Private Sub Form_Load()

        Set dbMyDb = OpenDatabase("C :\Documents and Settings\Shahid ul\My Documents\Compu ting Project\Databas e.mdb")
        Set rsDvd = dbMyDb.OpenReco rdset("DVD", dbOpenDynaset)

        If Not rsDvd.EOF Then rsDvd.MoveFirst
        Do While Not rsDvd.EOF
        lstdvd.AddItem rsDvd!DVD_no
        lstdvd.List(lst dvd.NewIndex) = rsDvd!Name
        rsDvd.MoveNext
        Loop

        Set rsMember = dbMyDb.OpenReco rdset("Member", dbOpenDynaset)

        If Not rsMember.EOF Then rsMember.MoveFi rst

        Do Until rsMember.EOF
        rsMember.MoveNe xt
        Loop


        End Sub

        Private Sub lstdvd_Click()

        Set rsDvd = dbMyDb.OpenReco rdset("DVD", dbOpenDynaset)

        txtdvdno.Text = rsDvd!DVD_no
        txtname.Text = rsDvd!Name
        txtTakendate.Te xt = rsDvd!Date_take n
        txtReturndate.T ext = rsDvd!Date_retu rn
        txtrent.Text = rsDvd!Renting_c ost
        txtbuy.Text = rsDvd!Buying_co st
        txtmemberid.Tex t = rsMember!Member _id
        txtFname.Text = rsMember!First_ name
        txtLname.Text = rsMember!Last_n ame
        End Sub[/CODE]

        So when I click on the list box selecting one data should be taken from the DVD table and show in the specified box and data from the Member table should do the same in their textboxes. But I get an error NO CURRENT RECORD or some other error after I've tried to fix it. Have you got any solutions for this please?
        Last edited by Killer42; Jul 5 '07, 11:45 PM. Reason: Added [CODE=vb] tag

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Can you tell us exactly where in the code the error occurs?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Another question. At lines 17 to 19, why are you reading all of the member records, if you're not going to do anything with them?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Hm... it seems to me that in the lstdvd_Click routine, when you try to access anything from rsMember, you have already (as mentioned in my prior post) moved past the end of this recordset, and so will produce an error.

              Comment

              • pureenhanoi
                New Member
                • Mar 2007
                • 175

                #8
                Originally posted by THEAF
                OK. What I meant was...
                I'm doing a school project. I'm making a system software for an internet cafe. For this I'm using Visual basic and Microsoft Access. I'm using this code:

                [CODE=vb]Private Sub Form_Load()

                Set dbMyDb = OpenDatabase("C :\Documents and Settings\Shahid ul\My Documents\Compu ting Project\Databas e.mdb")
                Set rsDvd = dbMyDb.OpenReco rdset("DVD", dbOpenDynaset)

                If Not rsDvd.EOF Then rsDvd.MoveFirst
                Do While Not rsDvd.EOF
                lstdvd.AddItem rsDvd!DVD_no
                lstdvd.List(lst dvd.NewIndex) = rsDvd!Name
                rsDvd.MoveNext
                Loop

                Set rsMember = dbMyDb.OpenReco rdset("Member", dbOpenDynaset)

                If Not rsMember.EOF Then rsMember.MoveFi rst

                Do Until rsMember.EOF
                rsMember.MoveNe xt
                Loop


                End Sub

                Private Sub lstdvd_Click()

                Set rsDvd = dbMyDb.OpenReco rdset("DVD", dbOpenDynaset)

                txtdvdno.Text = rsDvd!DVD_no
                txtname.Text = rsDvd!Name
                txtTakendate.Te xt = rsDvd!Date_take n
                txtReturndate.T ext = rsDvd!Date_retu rn
                txtrent.Text = rsDvd!Renting_c ost
                txtbuy.Text = rsDvd!Buying_co st
                txtmemberid.Tex t = rsMember!Member _id
                txtFname.Text = rsMember!First_ name
                txtLname.Text = rsMember!Last_n ame
                End Sub
                [/CODE]

                So when I click on the list box selecting one data should be taken from the DVD table and show in the specified box and data from the Member table should do the same in their textboxes. But I get an error NO CURRENT RECORD or some other error after I've tried to fix it. Have you got any solutions for this please?
                let see
                Code:
                    Set rsDvd = dbMyDb.OpenRecordset("DVD", dbOpenDynaset)
                ...............
                   Set rsMember = dbMyDb.OpenRecordset("Member", dbOpenDynaset)
                did u mean that DVD and Member are tables?
                Code:
                Set rsMember = dbMyDb.OpenRecordset("Member", dbOpenDynaset)    
                If Not rsMember.EOF Then rsMember.MoveFirst
                Do Until rsMember.EOF
                    rsMember.MoveNext
                Loop
                what does this code do?
                Code:
                Private Sub lstdvd_Click()
                Set rsDvd = dbMyDb.OpenRecordset("DVD", dbOpenDynaset)
                    txtdvdno.Text = rsDvd!DVD_no
                    txtname.Text = rsDvd!Name
                    txtTakendate.Text = rsDvd!Date_taken
                    txtReturndate.Text = rsDvd!Date_return
                    txtrent.Text = rsDvd!Renting_cost
                    txtbuy.Text = rsDvd!Buying_cost
                    txtmemberid.Text = rsMember!Member_id
                    txtFname.Text = rsMember!First_name
                    txtLname.Text = rsMember!Last_name
                End Sub
                here, u havent open rsMember yet. So, u cannot access to its rows. If u declare rsMember as a local varriable. It may havent been dispose at this possition but u moved its cursor to EOF at Do...Loop.
                i dont know the relation between DVD and Member table . If it has , u should make a Query to select datas on these two tables first. And then u can open this Query (as the same as open the table) to get datas. Otherwise, u donot have reason to get datas of two table at the same possition.
                if it's not a private, show me ur database structure and let me know what do u need for this program.

                Comment

                Working...