Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2006
Posts: 18
Reputation: shabina is an unknown quantity at this point 
Solved Threads: 0
shabina shabina is offline Offline
Newbie Poster

Listbox, ADODC

 
0
  #1
Jul 24th, 2006
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?! :-|
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 2
Reputation: Spook47 is an unknown quantity at this point 
Solved Threads: 1
Spook47 Spook47 is offline Offline
Newbie Poster

Re: Listbox, ADODC

 
0
  #2
Jul 24th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 18
Reputation: shabina is an unknown quantity at this point 
Solved Threads: 0
shabina shabina is offline Offline
Newbie Poster

Re: Listbox, ADODC

 
0
  #3
Jul 24th, 2006
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?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdAdd_click()
  2. ...
  3. Set wk1 = DBEngine.CreateWorkspace("MyWks", "admin", "", dbUseJet)
  4. Set db1 = wk1.OpenDatabase("c:\user.mdb", False)
  5. Set rs1 = db1.OpenRecordset("User", dbOpenDynaset)
  6. MsgBox "Add user", vbInformation
  7. rs3.AddNew
  8. rs3.Fields(0).Value = txtID.text
  9. rs3.Fields(1).Value = txtName.Text
  10. rs3.Fields(2).Value = txtAddress.Text
  11. rs3.Fields(3).Value = List1.Text
  12. rs3.Update
  13. txtID = ""
  14. txtName = ""
  15. txtAddress = ""
  16. List1.Clear
  17.  
  18. 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)
  1. Private Sub cmdModify_Click()
  2. If txtName.Text = "" And txtAddress.Text = ""
  3. ....
  4. Else
  5. MyResponse= MsgBox(" Save Changes ?", vbYesNo + vbExclamation)
  6. If MyResponse= 6 Then
  7. cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=c:\user.mdb; Persist Security Info=false"
  8. rs1.Open "select * from User", cn1, adOpenDynamic
  9. cn1.BeginTrans
  10. sql = "update User set " & _
  11. "Name = '" & txtName.Text & "', " & _
  12. "Address = '" & txtAddress.Text & "', " & _
  13. "EmailAttachment='" & List1.Text & "' where ID = " & txtID.Text
  14. cn1.Execute sql
  15. MsgBox "User Updated", vbInformation cn1.CommitTrans
  16. Adodc1.Refresh
  17. rs1.Close
  18. cn1.Close
  19. Adodc1.Recordset.MoveNext
  20. txtID.Text = Adodc1.Recordset.Fields(0).Value
  21. txtName.Text = Adodc1.Recordset.Fields(1).Value
  22. txtAddress.Text = Adodc1.Recordset.Fields(2).Value
  23. List1.Text = Adodc1.Recordset.Fields(3).Value
  24.  
  25. ElseIf MyResponse = 7 Then
  26. Exit Sub
  27. End If
  28. End If
  29. End Sub
Last edited by Comatose; Jul 24th, 2006 at 1:15 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 45
Reputation: maheshsayani is an unknown quantity at this point 
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Re: Listbox, ADODC

 
0
  #4
Jul 24th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 18
Reputation: shabina is an unknown quantity at this point 
Solved Threads: 0
shabina shabina is offline Offline
Newbie Poster

Re: Listbox, ADODC

 
0
  #5
Aug 4th, 2006
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
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 28
Reputation: mjwest10 is an unknown quantity at this point 
Solved Threads: 3
mjwest10 mjwest10 is offline Offline
Light Poster

Re: Listbox, ADODC

 
0
  #6
Mar 6th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 18
Reputation: shabina is an unknown quantity at this point 
Solved Threads: 0
shabina shabina is offline Offline
Newbie Poster

Re: Listbox, ADODC

 
0
  #7
Mar 6th, 2007
thanks Matt, its of really gr8 help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC