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

How do I search 6 fields with one combobox 1

Status
Not open for further replies.

cheekeemonki

Technical User
Joined
May 3, 2009
Messages
5
Location
US
Any help is greatly appreciated!!!!

I have already created a dialog box that holds the Combobox that contains the list of searchable terms but I am getting stuck on my search/go button. I either need to create a Macro, query or Vb code that will all allow me to search the information in the combobox against the 6 fields in a query.

Any suggestions on the best way to tackle this problem?

Thanks!
 
This is a sample code that searches Employee Table
You can change the SQL to search only those fixed fields
Code:
Private Sub cmdSearch_Click()
    Dim dbConnection As ADODB.Connection
    Set dbConnection = CurrentProject.Connection

    Dim rsSearch As ADODB.Recordset
    Set rsSearch = New ADODB.Recordset

    Dim strSearch As String
    strSearch = Me.txtSearch

    Dim strSQLSearch As String
    strSQLSearch = "SELECT * FROM Employees"
    rsSearch.Open strSQLSearch, dbConnection, adOpenKeyset, adLockOptimistic

    Do While Not rsSearch.EOF
        For Each fld In rsSearch.Fields
            If fld.Value = txtSearch Then
                MsgBox rsSearch!EmpID
                Exit Sub
            End If
        Next
        rsSearch.MoveNext
    Loop
End Sub
There is an exit sub on the first find. You can change it search more.

Zameer Abdulla
 
I am not sure how to apply your suggestions... Here is a copy of the DB Event Search form in question. I have listed the sample fields as Event 1 - Event 6.

The query "EVENT SEARCH" contains combined data from two forms that I would like to search.

In the test db I have two names in the drop down menu... Ron Pressman and Jack Touble... The combobox search should only pull up the records that contain the selected name in any of the 6 event fields.

Thanks again for any help with this issue.
 
 http://cheekeemonki.angelfire.com/Event_TESTER.accdb
cheekeemonki said:
6 event fields
sounds quite un-normalized. Without downloading your file, can you tell us about your application specifically this table?

Are you hoping to use the query as the record source of a form or report?

Duane
Hook'D on Access
MS Access MVP
 
Duane... It will only be used for mail merges and a quick reference.
 
If I understand correctly, you could have a simple select query with SQL like:
Code:
SELECT *
FROM [YourBaseQuery]
WHERE Field1 = [Forms]![frmYourForm]![cboYourCBO] OR
Field2 = [Forms]![frmYourForm]![cboYourCBO] OR
Field3 = [Forms]![frmYourForm]![cboYourCBO] OR
Field4 = [Forms]![frmYourForm]![cboYourCBO] OR
Field5 = [Forms]![frmYourForm]![cboYourCBO] OR
Field6 = [Forms]![frmYourForm]![cboYourCBO];


Duane
Hook'D on Access
MS Access MVP
 
Duane, I wonder if the following works in JetSQL:
Code:
SELECT *
FROM [YourBaseQuery]
WHERE [Forms]![frmYourForm]![cboYourCBO] In ([Field1],[Field2],[Field3],[Field4],[Field5],[Field6])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hey Thanks Duane!!! All is up and running
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top