Results 1 to 4 of 4

Thread: Populate Grid with selected from another Grid

  1. #1
    Guest

    Unhappy

    I have loaded a table into a DBGrid control, and I want
    to be able to click on a particular selection from the
    fldOrderID column and when that selection is made a second
    DBGrid populates with a table containing a tblOrderDetail table with matching fldOrderID that was selected in first grid
    Heres what I have tried

    I made a button
    Private Sub Command1_Click()
    datOrderDetail.RecordSource = "SELECT * FROM tblOrderDetail " & _
    " WHERE fldOrderID = " & _
    dbgOrderMaster.Columns(0).Value
    datOrderDetail.Refresh
    End Sub

    the second DBGrid dbgOrderDetail only show the field headers from the table tblOrderDetail and shows no records
    I tried variations of the select like

    datOrderDetail.RecordSource = "SELECT * FROM tblOrderDetail " & _
    " WHERE fldOrderID = " & _
    dbgOrderMaster.Columns("fldOrderID").Value


    Same results

    What event would I put a working select into to make the
    second Grid show info when a selection in the fldOrderID
    was made in the first Grid?


    The first Grid Is successfully populated with this
    datOrderMaster.RecordSource = "Select * from tblOrderMaster where fldCustomerID like " & "'*" & glngCustomerID & "*'"


  2. #2
    Addicted Member curlywink's Avatar
    Join Date
    Mar 2000
    Location
    Manila, Philippines
    Posts
    141

    Talking

    Hi there,

    Why don't ya try, inserting your code in your reposition event ...

    Private Sub Data1_Reposition
    datOrderDetail.RecordSource = "SELECT * FROM tblOrderDetail " & _
    " WHERE fldOrderID = " & _
    dbgOrderMaster.Columns("fldOrderID").Value
    datOrderDetail.Refresh
    End sub


    Hope this works ...

  3. #3
    Your code is correct.

    Make sure that there is space character before 'WHERE' in the query

    May be the table names or field names you specified are wrong.
    or may be there are no records in orderdetails table.

    [Edited by gorthims on 05-04-2000 at 04:29 AM]

    [Edited by gorthims on 05-04-2000 at 04:32 AM]

  4. #4
    Guest
    Yes the field names are right and yes there are records in tlbOrderDetails I have opened that table and looked at it.

    curlywink I wasnt aware the reposistion event for a datacontrol happened when a cell in a dbgrid control bound to that datacontrol was clicked. Also the first DBGrid has its seperate data control bound to it, and the second one has its own seperate data control so when I click on a cell in the first grid that would not cause any event in the second grids data control anyway.
    Ive been working on something else but will get back to this soon.
    Thanks for trying to help

    2 grids
    first one is populated with records that match a preselected fldCustomerID. Click on a cell (fldOrderID) in one of the records in the first Grid and the second grid is populated with all records matching that fldOrderID, and whenever a differnet fldOrderID in the firs Grid is clicked the second one is re-populated to match that fldOrderID. that is what I am trying to to do.

    [Edited by VB_Sponge on 05-04-2000 at 09:14 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width