how to retrieve data

Reply

Join Date: Apr 2009
Posts: 8
Reputation: snta is an unknown quantity at this point 
Solved Threads: 0
snta snta is offline Offline
Newbie Poster

how to retrieve data

 
0
  #1
Apr 13th, 2009
i'm new programmer. can u help me , how to retrieve data from database(access) and display in combo box. the value in combo box will automatic display into text box
example:
dtbs=office.mdb
table name= item
field name=itemID,itemName
itemID=M1; itemName=modem
itemID=M2; itemName=repeater

i want this combo box display all itemID in combo box. if the user choose/click, M1, text box will display 'modem' automatically....
how to do like that???plzz help me.....
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,085
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 89
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: how to retrieve data

 
0
  #2
Apr 13th, 2009
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: snta is an unknown quantity at this point 
Solved Threads: 0
snta snta is offline Offline
Newbie Poster

Re: how to retrieve data

 
0
  #3
Apr 13th, 2009
Originally Posted by cguan_77 View Post
check out this link

http://en.allexperts.com/q/Visual-Ba...earch-form.htm
this example for text box,but now i using combo box (style drop down list).
how to do that???
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,068
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 123
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: how to retrieve data

 
0
  #4
Apr 14th, 2009
1. open the recordset only for itemID
2. in a for loop add the items to combobox
3. open another recordset for itemname by passing itemID in where clause at runtime dynamically by selecting the itmes from combobox
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: snta is an unknown quantity at this point 
Solved Threads: 0
snta snta is offline Offline
Newbie Poster

Re: how to retrieve data

 
0
  #5
Apr 14th, 2009
thank you very much for your help
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: how to retrieve data

 
0
  #6
Apr 14th, 2009
Originally Posted by snta View Post
i'm new programmer. can u help me , how to retrieve data from database(access) and display in combo box. the value in combo box will automatic display into text box
example:
dtbs=office.mdb
table name= item
field name=itemID,itemName
itemID=M1; itemName=modem
itemID=M2; itemName=repeater

i want this combo box display all itemID in combo box. if the user choose/click, M1, text box will display 'modem' automatically....
how to do like that???plzz help me.....
think thats the complete code for you....take a combo box and a textbox...

set properties :-

combox box : name --> cboItem
style --> 2- dropdown list
textbox : name --> txtname

add this reference in the project --> Microsoft Activex Data Object <version no.> Library.......the version no. depends on the version of ms office u have installed.....take the highest one for better performance....

here we go...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Dim gcn As New ADODB.Connection
  4.  
  5. Private Sub cboItem_Click()
  6. Dim rs As New ADODB.Recordset
  7.  
  8. With rs
  9. .CursorLocation = adUseClient
  10. .LockType = adLockOptimistic
  11. .CursorType = adOpenDynamic
  12. .Open "select itemname from [item] where itemid='" & cboItem.List(cboItem.ListIndex) & "'", gcn
  13.  
  14. txtname.Text = IIf(.RecordCount = 0, "", IIf(IsNull(!itemname), "", !itemname))
  15. End With
  16.  
  17. If rs.State = adStateOpen Then rs.Close
  18. Set rs = Nothing
  19. End Sub
  20.  
  21. Private Sub Form_Load()
  22. On Error GoTo err1
  23.  
  24. gcn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sample.mdb;" & _
  25. "Persist Security Info=False"
  26. gcn.Open
  27.  
  28. Call PopulateCombo
  29.  
  30. Exit Sub
  31.  
  32. err1:
  33. Err.Clear
  34. MsgBox "Could not open database.", vbCritical, "Error"
  35. If gcn.State = adStateOpen Then gcn.Close
  36. Set gcn = Nothing
  37. End Sub
  38.  
  39. Private Sub PopulateCombo()
  40. Dim rs As New ADODB.Recordset
  41.  
  42. rs.CursorLocation = adUseClient
  43. rs.LockType = adLockOptimistic
  44. rs.CursorType = adOpenDynamic
  45. rs.Open "select itemid from [item] order by itemid", gcn
  46.  
  47. With cboItem
  48. .Clear
  49. .AddItem "Select an Item Id"
  50. .ListIndex = 0
  51. If rs.RecordCount > 0 Then
  52. rs.MoveFirst
  53. While Not rs.EOF()
  54. .AddItem rs!itemid
  55. rs.MoveNext
  56. Wend
  57. .ListIndex = 1
  58. End If
  59. End With
  60.  
  61. If rs.State = adStateOpen Then rs.Close
  62. Set rs = Nothing
  63. End Sub
  64.  
  65. Private Sub Form_Unload(Cancel As Integer)
  66. If gcn.State = adStateOpen Then gcn.Close
  67. Set gcn = Nothing
  68.  
  69. End
  70. End Sub

please let me know if this works out for you....for any more questions feel free to ask...

regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: how to retrieve data

 
0
  #7
Apr 17th, 2009
it seems that u have already benefited.....have u got ur answer...

if yes then please mark this thread as SOLVED
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC