943,083 Members | Top Members by Rank

Ad:
Apr 13th, 2009
0

how to retrieve data

Expand 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.....
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
snta is offline Offline
8 posts
since Apr 2009
Apr 13th, 2009
0

Re: how to retrieve data

Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
Apr 13th, 2009
0

Re: how to retrieve data

this example for text box,but now i using combo box (style drop down list).
how to do that???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
snta is offline Offline
8 posts
since Apr 2009
Apr 14th, 2009
0

Re: how to retrieve data

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
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,402 posts
since Feb 2007
Apr 14th, 2009
0

Re: how to retrieve data

thank you very much for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
snta is offline Offline
8 posts
since Apr 2009
Apr 14th, 2009
0

Re: how to retrieve data

Click to Expand / Collapse  Quote originally posted by snta ...
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
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 17th, 2009
0

Re: how to retrieve data

it seems that u have already benefited.....have u got ur answer...

if yes then please mark this thread as SOLVED
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Split PDF using Vb6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Adding value of two rptfunction





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC