| | |
Listbox, ADODC
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2006
Posts: 18
Reputation:
Solved Threads: 0
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?! :-|
any ideas on listbox with adodc?! :-|
•
•
Join Date: Jul 2006
Posts: 18
Reputation:
Solved Threads: 0
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?
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.
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?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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.AddNew rs3.Fields(0).Value = txtID.text rs3.Fields(1).Value = txtName.Text rs3.Fields(2).Value = txtAddress.Text rs3.Fields(3).Value = List1.Text rs3.Update txtID = "" txtName = "" txtAddress = "" List1.Clear 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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub cmdModify_Click() If txtName.Text = "" And txtAddress.Text = "" .... Else 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 cn1.BeginTrans 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 Adodc1.Refresh rs1.Close cn1.Close Adodc1.Recordset.MoveNext 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
Last edited by Comatose; Jul 24th, 2006 at 1:15 am.
•
•
Join Date: Jul 2006
Posts: 18
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by maheshsayani
Hi
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
•
•
Join Date: Feb 2007
Posts: 28
Reputation:
Solved Threads: 3
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
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
![]() |
Similar Threads
- listbox hiccup (Visual Basic 4 / 5 / 6)
- listbox (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Frustrated Newbie!!
- Next Thread: Data report
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





