By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,644 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,644 IT Pros & Developers. It's quick & easy.

retrieving more than 1 row in access with datagrid

P: 44
Here's my code:

Private Sub cboSKP_Click()
Dim rs6 As New ADODB.Recordset

With rs6
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.CursorType = adOpenStatic
.Source = "SELECT * FROM Products WHERE NoProd = '" & cboProd.Text & "'"
.Open
If cboProd.ListIndex > -1 Then
cboCust.Text = rs6(3)
Dim rs8 As New ADODB.Recordset
With rs8
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.CursorType = adOpenStatic
.Source = "SELECT * FROM Ms_Cust WHERE Code = '" & cboCust.Text & "'"
.Open
If cboCust.Text = rs6(3) Then
lblSalesMan.Caption = rs8(8)
lblCompName.Caption = rs8(1)
lblAdd.Caption = rs8(2)
End If
cboTerm.Text = rs6(4)
txtDue.Text = rs6(5)
End With

If cboProd.Text = rs6(0) Then
rs(0).Value = rs6(6)
rs(2).Value = rs6(7)
End If




End If






.Close
End With

End Sub
I'm using VB6, ADODB, and MsAccess as for the database.
Using the combobox as the key to display all of records from the table.
For NoProd = Prod001 has 3 records : candybar, chocolate, sweets
When i change the combobox of NoProd to Prod001,
But why my datagrid show only candybar?
Nov 28 '07 #1
Share this Question
Share on Google+
2 Replies


lotus18
100+
P: 866
Hi
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSKP_Click()
  2. Dim rs6 As New ADODB.Recordset
  3.  
  4. With rs6
  5. .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
  6. .CursorLocation = adUseClient
  7. .LockType = adLockOptimistic
  8. .CursorType = adOpenStatic
  9. .Source = "SELECT * FROM Products WHERE NoProd = '" & cboProd.Text & "'"
  10. .Open
  11. If cboProd.ListIndex > -1 Then
  12. cboCust.Text = rs6(3)
  13. Dim rs8 As New ADODB.Recordset
  14. With rs8
  15. .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
  16. .CursorLocation = adUseClient
  17. .LockType = adLockOptimistic
  18. .CursorType = adOpenStatic
  19. .Source = "SELECT * FROM Ms_Cust WHERE Code = '" & cboCust.Text & "'"
  20. .Open
  21. If cboCust.Text = rs6(3) Then
  22. lblSalesMan.Caption = rs8(8)
  23. lblCompName.Caption = rs8(1)
  24. lblAdd.Caption = rs8(2)
  25. End If
  26. cboTerm.Text = rs6(4)
  27. txtDue.Text = rs6(5)
  28. End With
  29.  
  30. If cboProd.Text = rs6(0) Then
  31. rs(0).Value = rs6(6)
  32. rs(2).Value = rs6(7)
  33. End If
  34.  
  35.  
  36. End If
  37.  
  38.  
  39.  
  40. .Close
  41. End With
  42.  
  43. End Sub
  44.  
Where's your code on filling up your datagrid?

If I were you, I'll create a module for your Active Connection to call it and it helps you minimize your coding : )

Rey Sean
Nov 29 '07 #2

P: 44
it is here
Expand|Select|Wrap|Line Numbers
  1. If cboProd.Text = rs6(0) Then
  2. rs(0).Value = rs6(6)
  3. rs(2).Value = rs6(7)
  4. End If
where it means if item we choose on the combobox(cboProd) are same as in database(rs6(0)), it will display the rest of the record at datagrid (rs) whereis item=rs6(0)
eg: if i choose Prod001 from combobox, the datagrid will show candybar, chocolate, sweets (in row) but my code only show one item 'candybar'.
got any solutions?

i hope u get what i mean =)
thank you..
Nov 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.