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

Searching using cascading combo boxes

Status
Not open for further replies.

subtlesnake

Technical User
Mar 19, 2005
5
GB
I can search using a single combo box using the "find a record on my form based on the value I selected in my combo box" option in the combo box wizard.

However, I can only search by the field I choose in the wizard. I want a second combo box to pick the field to serach by.

How would I do this?
 
Create another combo box on your form using the wizard again but this time select the second field you want to search on.

Is this what you mean


Program Error
Why is it, I still think in terms of spectrum BASIC!
 
No, I mean I want to be able to change the field "to search on" using another combo box. So the other combo box would have every field, and I'd select title to search by title, or author to search by author.
 
Better to have some Option buttons and Select case statements. Then have different SQL inside functions. These functions will be same as the "find record based on ...."

Then

'====sample====
Case 1
Function1
Case 2
Function2
end select
'===end=====
hope this helps
or please come back

Zameer Abdulla
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
Option 1:
Create a table with your fields, then use that as your rowsource for the second combobox.

Option 2:
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strFields As String
Dim i As Integer
    
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM tblTest")
For i = 0 To rs.Fields.count - 1
    strFields = strFields & Chr(34) & rs.Fields(i).Name & Chr(34) & ";"
Next
strFields = Left(strFields, Len(strFields) - 1)
Combo2.RowSourceType = "Value List"
Combo2.RowSource = strFields

"SELECT * FROM tbl WHERE " & Combo2 & "='" & Combo1 & "'"

This assume all fields are text data type. You'll need to adjust the coding to handle numbers and dates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top