Solved

Display multiple search results on one form

Posted on 2014-03-24
4
175 Views
1 Endorsement
Last Modified: 2014-08-08
In a Access 2007 database I'm trying to do a generic search-for example a street name.  I would like for every instance of that particular street to appear on one single form.  Is that possible?  Thanks for any help.
1
Comment
Question by:EASCOA
  • 2
4 Comments
 
LVL 84
ID: 39950526
Are you searching a single table and field? Or are you trying to do a "full text" search, like in SQL Server?

A single able/field is fairly easy, and multiple tables/fields aren't much more difficult (just more work).

Full text is another matter ...
0
 

Author Comment

by:EASCOA
ID: 39950578
Actually I'm trying to search a single table for now and a single field..example-location address field.  I'm looking for anything in that address field.  Example  (directional) "NW" , (street name) "Houston", or (house location) "2034".  Thanks again for any help.
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39950654
The following is a picture of a search form and a picture of its results form and the code behind the search.  The results form contains a hyper link to open the full record where it may be edited.

Search Form
Option Compare Database
Option Explicit

Private Sub cmdBrowse_Click()
    Me.txtPath = fChooseDirectory()
End Sub

Private Sub cmdClear_Click()
Dim ctl As Control

    For Each ctl In Me.Controls
        Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acCheckBox
                ctl = Null
        End Select
    Next ctl
    Set ctl = Nothing
    
    Me.fraStatus = 1
End Sub

Private Sub cmdExit_Click()
    Call CommonExit(Me)
End Sub

Private Sub cmdExportList_Click()
    Dim sFileName
    Me.txtPath.Visible = True
    Me.cmdBrowse.Visible = True
    If Me.txtPath & "" = "" Then
        MsgBox "A path is required.", vbOKOnly
        Me.txtPath.SetFocus
        Exit Sub
    End If
    sFileName = Me.txtPath & "\ClientList_" & Format(Date, "yyyymmdd") & ".xlsx"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qClientList", sFileName
End Sub

Private Sub cmdViewResults_Click()
   On Error GoTo Err_Proc

    Call BuildSQL
    DoCmd.OpenForm "frmSearchResults", , , , , , Me.name
    Me.Visible = False

Exit_Proc:
   On Error GoTo 0
   Exit Sub

Err_Proc:

    Select Case err.Number
        Case Else
            MsgBox "Error " & err.Number & " (" & err.Description & ") in procedure cmdViewResults_Click of VBA Document Form_frmClientSearch"
    End Select
End Sub

Public Sub BuildSQL()
Dim strSQL As String
Dim strSelect As String
Dim strWhere As String
Dim strCondition As String
Dim strOrderBy As String

    strSelect = "Select * from tblClients "
    strOrderBy = " ORDER BY LastName, FirstName"
    strWhere = ""
    
    If Me.txtFirstName & "" = "" Then
    Else
        strWhere = "FirstName Like " & QUOTE & Me.txtFirstName & "*" & QUOTE
    End If
    If Me.txtLastName & "" = "" Then
    Else
        strCondition = "LastName Like " & QUOTE & Me.txtLastName & "*" & QUOTE
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.txtcity & "" = "" Then
    Else
        strCondition = "City Like " & QUOTE & Me.txtcity & "*" & QUOTE
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.chkBUP = True Then
        strCondition = "BUP = True"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.cboCareMgrID & "" = "" Then
    Else
        strCondition = "CareMgrID = " & Me.cboCareMgrID
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.cboGenderID & "" = "" Then
    Else
        strCondition = "GenderID = " & Me.cboGenderID
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.txtZip & "" = "" Then
    Else
        strCondition = "Zip = '" & Me.txtZip & "'"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.cboRaceID & "" = "" Then
    Else
        strCondition = "RaceID = " & Me.cboRaceID
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.cboDiagnosis & "" = "" Then
    Else
        strCondition = "Diagnosis = '" & Me.cboDiagnosis & "'"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.txtpid & "" <> "" Then
        strCondition = "PID = '" & Me.txtpid & "'"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.txtClientID & "" <> "" Then
        strCondition = "ClientID = " & Me.txtClientID
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.txtems & "" <> "" Then
        strCondition = "EMS = '" & Me.txtems & "'"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
        
    If Me.cboLevelID & "" <> "" Then
        strCondition = "LevelID = " & Me.cboLevelID
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.chkMFP = True Then
        strCondition = "MFP = True"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.chkT19 = True Then
        strCondition = "T19 = True"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.chkCHCPD = True Then
        strCondition = "Cat4 = True"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    If Me.chkSelf = True Then
        strCondition = "Self = True"
        If strWhere = "" Then
            strWhere = strCondition
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If
    
    Select Case Me.fraStatus
        Case 1
            strCondition = "StatusID = 1318"          'Open
        Case 2
            strCondition = "StatusID = 1319"          'Closed
        Case Else
            strCondition = ""
    End Select
    If strWhere = "" Then
        If strCondition = "" Then
        Else
            strWhere = strCondition
        End If
    Else
        If strCondition = "" Then
        Else
            strWhere = strWhere & " AND " & strCondition
        End If
    End If   
    
    
    If strWhere = "" Then
        strSQL = strSelect
    Else
        strSQL = strSelect & " WHERE " & strWhere
    End If

    strSQL = strSQL & strOrderBy
    Me.txtQuery = strSQL
End Sub

Private Sub Form_Close()
    Call CommonClose(Me)
End Sub

Open in new window

SearchResultsForm.JPG
0
 

Author Closing Comment

by:EASCOA
ID: 40249319
Thanks for all the help unfortunately the client went another direction.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question