Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating a DB Grid With Columns from 2 different tables

Status
Not open for further replies.

newora

Programmer
Aug 19, 2003
133
GB
Hi There,

I have been trying to protype this for a few hours and do not seem to be getting anywhere, so could someone please help point me in the right direction.

I have a DB table that has 2 columns in it - I only wish one of these columns to be displayed in the DB grid. I also want another column in the DB grid that contains a column from another DB table. I am OK with doing this, but my problem comes when I want to make the second DB grid column a drop down list, based upon the contents of a column from a second db table.

eg.

Column1 column2
dbtbl1.machinename dbtbl2.fault_reasons(dropdown)

Any pointers would be most welcome
 
First, I would populate a combo box set to DropDown List style:
Code:
rst1.Open "Select fault_reasons From dbtbl2", Cn

cboFault.Clear
For i = 1 To rst1.RecordCount
    cboFault.AddItem rst1!fault_reasons
    rst1.MoveNext
Next i

rst1.Close
cboFault.ListIndex = 0

And then in cboFault_Click event I would populate grid:

Code:
rst1.Open "Select machinename From dbtbl1 Where Col2 = " & cboFault.Text, Cn

Grid.Clear

for i = 1 To rst1.RecordCount
    grid.additem rst1!machinename 
    rst1.MoveNext
Next i


HTH

---- Andy
 
Hi, Thanks for that - it has certainly put me on the right track.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top