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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Combobox choice to populate a datagrid?

Status
Not open for further replies.

Sideman

Technical User
Apr 21, 2003
41
US
First, let me state that I'm a beginner, but I have been studing many instructional books on VB programming. I'm using VB6-SP5 with an Access 2000 database. Things have gone pretty well until I got stuck attempting the following...
I'm using a Tab control to display several groupings of 'like' customer data on different tabs. Tab(0) displays basic Customer info in text boxes. Tab(1) displays the Customer's equipment via a DataGrid control and some text boxes. I'm using a DataCombo box on Tab(0) to select a Customer name from the "Customers" table and populate the text boxes on Tab(0) and this works great. BUT, when I try using the unique Customer Number from the "Customer" table to find and display all related equipment records from a second "Equipment" table (based on the same Customer Number) on Tab(1) the data never changes in the DataGrid. I've tried ADODC controls, Data Environment Designer, and ODBC data sources. I obviously don't have a clue how to accomplish my goals. I think I don't understand the relationship between finding the records and then refreshing the grid data to display it.
I'v tried several approaches described in books and in on-line examples but to no avail. It seems either nobody does things like this (un-likely), or my glaring lack of knowledge is all too apparent.
I would appreciate it so very much if someone could point me in the right direction as I am quite lost and frustrated.
Thank you, in advance, for considering a solution.
 
Here is the code that I have used to refresh data on a grid bound to an ADODC. The code is in the Combo click event in my example.

Private Sub Combo1_Click()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Select * From [Table1] Where [Field1]='" & Combo1.Text & "';"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub

The variable 'Combo1.text' can be switched for another variable. If the field1 type is numeric then you will need to drop the single quotes in the SQL statement.


Thanks and Good Luck!

zemp
 
Thank you, Zemp, for your quick reply. You are very kind to share your expertise with me. I will try your suggestion and let you know how things turn out. My hopes are renewed!!


Of all the things I've lost, I miss my mind the most!
 
Zemp, sorry for the late reply...your tip was spot on!! It gave me the details I needed and I'm trudging on with my project. All is well with the world...(chuckle).
Thank you.

Of all the things I've lost, I miss my mind the most!
Sideman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top