i have a problem in trying to link my listbox with its respective field in the database. when i run my program in vb6, i get all the other records populated into my form when i click on the ADODC but i couldn't get the info i entered in my listbox displayed...and in my report in MSAccess, it only shows me only one item in the list instead of, say i added 3items!

any ideas on listbox with adodc?! :-|

Recommended Answers

All 6 Replies

If you would give me some more info ie properties of the list box and where you have linked it I may be able to help.

i have 2 textboxes and 2listboxes where List1 contains the filename and List2 has its respective path and is hidden. i have an ADODC to connect to my database, when i run program, the textboxes are populated with the records as i click on the adodc but the listbox doesn't seem to work. what i want is that when i click on the adodc and shows a particular user(record), it should also show me if i have added some email attachments in the listbox, but if there's no item in the listbox, then should just leave it blank/cleared.
below is my piece of code:

1. when i add a new user, i am able to view the person's record,name and address, but if i add some email attachments to the record, it doesn't get added to the respective field 'email' in my database. any ideas?

Private Sub cmdAdd_click()
Set wk1 = DBEngine.CreateWorkspace("MyWks", "admin", "", dbUseJet)
        Set db1 = wk1.OpenDatabase("c:\user.mdb", False)
        Set rs1 = db1.OpenRecordset("User", dbOpenDynaset)
        MsgBox "Add user", vbInformation
        rs3.Fields(0).Value = txtID.text
        rs3.Fields(1).Value = txtName.Text
        rs3.Fields(2).Value = txtAddress.Text
        rs3.Fields(3).Value = List1.Text
        txtID = ""
        txtName = ""
        txtAddress = ""
End Sub

2. this is the code for when i want to update any changes made to any record. clicking on adodc need to show the appropriate email attachments in List1 and should be cleared if that user has no attachments added. meanwhile, this doesn't seem to work.

Private Sub cmdModify_Click()
If txtName.Text = "" And txtAddress.Text = ""         
        MyResponse= MsgBox(" Save Changes ?", vbYesNo + vbExclamation)
        If MyResponse= 6 Then
            cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=c:\user.mdb; Persist Security Info=false"
            rs1.Open "select * from User", cn1, adOpenDynamic
            sql = "update User set " & _
            "Name = '" & txtName.Text & "', " & _
            "Address = '" & txtAddress.Text & "', " & _
            "EmailAttachment='" & List1.Text & "' where ID = " & txtID.Text
            cn1.Execute sql
            MsgBox "User Updated", vbInformation            cn1.CommitTrans
        txtID.Text = Adodc1.Recordset.Fields(0).Value
        txtName.Text = Adodc1.Recordset.Fields(1).Value
        txtAddress.Text = Adodc1.Recordset.Fields(2).Value
        List1.Text = Adodc1.Recordset.Fields(3).Value
        ElseIf MyResponse = 7 Then
            Exit Sub
        End If
    End If
End Sub

Your code for rs3.Fields(3).Value = List1.Text has to be change

Try changing code like
rs3.Fields(3).Value = List1.list(itemnumber)

'itemnumber is the element you want to assign from list box

Your code for rs3.Fields(3).Value = List1.Text has to be change

Try changing code like
rs3.Fields(3).Value = List1.list(itemnumber)

'itemnumber is the element you want to assign from list box

i'm not really familiar with using itemnumber, so u mind pointing me in the right direction as i am a beginner in this field.

itemnumber is the number of the item in the list you want to display. I think you want to use the text for the selected item so you would use this code:

rs3.Fields(3.Value) = List1.List(List1.ListIndex)

If you are just starting I would suggest reading this Beginners VB6 Guide I also have a VB6 Database Guide. Both these would help you a lot in learning this stuff. I hope this helps

thanks Matt, its of really gr8 help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.