Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display multiple search results on one form

Posted on 2014-03-24
4
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85
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 39

Accepted Solution

by:
PatHartman earned 2000 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

718 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