retrieving more than 1 row in access with datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WhiteShore
    New Member
    • Nov 2007
    • 44

    retrieving more than 1 row in access with datagrid

    Here's my code:

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

    With rs6
    .ActiveConnecti on = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
    .CursorLocation = adUseClient
    .LockType = adLockOptimisti c
    .CursorType = adOpenStatic
    .Source = "SELECT * FROM Products WHERE NoProd = '" & cboProd.Text & "'"
    .Open
    If cboProd.ListInd ex > -1 Then
    cboCust.Text = rs6(3)
    Dim rs8 As New ADODB.Recordset
    With rs8
    .ActiveConnecti on = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
    .CursorLocation = adUseClient
    .LockType = adLockOptimisti c
    .CursorType = adOpenStatic
    .Source = "SELECT * FROM Ms_Cust WHERE Code = '" & cboCust.Text & "'"
    .Open
    If cboCust.Text = rs6(3) Then
    lblSalesMan.Cap tion = rs8(8)
    lblCompName.Cap tion = 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?
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Hi
    [code=vb]
    Private Sub cboSKP_Click()
    Dim rs6 As New ADODB.Recordset

    With rs6
    .ActiveConnecti on = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
    .CursorLocation = adUseClient
    .LockType = adLockOptimisti c
    .CursorType = adOpenStatic
    .Source = "SELECT * FROM Products WHERE NoProd = '" & cboProd.Text & "'"
    .Open
    If cboProd.ListInd ex > -1 Then
    cboCust.Text = rs6(3)
    Dim rs8 As New ADODB.Recordset
    With rs8
    .ActiveConnecti on = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & NmDatabase & ";Persist Security Info=False"
    .CursorLocation = adUseClient
    .LockType = adLockOptimisti c
    .CursorType = adOpenStatic
    .Source = "SELECT * FROM Ms_Cust WHERE Code = '" & cboCust.Text & "'"
    .Open
    If cboCust.Text = rs6(3) Then
    lblSalesMan.Cap tion = rs8(8)
    lblCompName.Cap tion = 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
    [/code]

    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

    Comment

    • WhiteShore
      New Member
      • Nov 2007
      • 44

      #3
      it is here
      Code:
      If cboProd.Text = rs6(0) Then
      rs(0).Value = rs6(6)
      rs(2).Value = rs6(7)
      End If
      where it means if item we choose on the combobox(cboPro d) 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..

      Comment

      Working...