PDA

View Full Version : Thanls...and a new one...combo to contents of a table;



mud2
04-02-2006, 09:20 AM
I have three tables...table1, table2, and table3. Table3 contains the names "table1" and "table2". Combo1's recordsource is Table3. Combo2's recordSource is Combo1.value. This works fine. I can have combo2 display the contents of either table1 or table2.
Now the problem:
How do I get combo2 to display ONLY those records in its RecordSource that meet certain conditions? I.e., Show those records in the chosen table where that tables field1 = 77 ?
How do I write the "WHERE" in the SELECT FROM ?
Thanks!

afortuno
04-02-2006, 10:43 AM
Mud2,

Ok, you've got a combo box that needs to pull its values dynamically. The values provided need to come from a specified table. The value also needs to be filtered by some other value.
Consider creating a function (or sub procedure) that dynamically builds and assigns the RecordSource to ComboBoxTwo.


Function InitComboBoxTwo ()
Dim strSql as String

Let strSql = "SELECT field FROM " & ComboBoxOne.Value & " "
Let strSql = strSql & "WHERE field = " & TextBox.Value & ";"

Let ComboBoxTwo.RecordSource = strSql
Let ComboBoxTwo.RecordSourceType = "Table/Query"
End Function

Whenever the source values (e.g. ComboBoxOne) changes, you need to reassign ComboBoxTwo's values. To do this, I would call the function you just created from the "OnChange" event of the combo box, text box, list box, etc.

You'll want to tweak the Init...() function to suite your needs, but this should work nicely.

Cheers,
Adam