Results 1 to 3 of 3

Thread: Wildcard search not working. [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    40

    Resolved Wildcard search not working. [RESOLVED]

    Hi,
    I have created a form to search a database using wildcard searches.
    In my database I have a column named Asbestos Type. In this column I have three different values; 'Chrysotile', 'Amosite' and 'Chrysotile and Amosite'.
    When I search for Chrysotile, both 'Chrysotile' and 'Chrysotile and Amosite' are returned. When I search for Amosite only 'Amosite' is returned. Does anyone know what could be causing this?
    Thanks in advance for the help.

    VB Code:
    1. Option Explicit
    2. Private rsSearch As ADODB.Recordset
    3. Private cn As ADODB.Connection
    4.  
    5. Private Sub Form5_Load()
    6. LoadTheGrid "SELECT * FROM Asbestos"
    7. End Sub
    8.  
    9. Private Function GetRecordset(ByVal strSQL As String) As ADODB.Recordset
    10. Set cn = New ADODB.Connection
    11. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source = C:\Documents and Settings\Harry Scott\My Documents\Homework\Computing\Asbestos Register\Database.mdb"
    12. cn.CursorLocation = adUseClient
    13. cn.Open
    14. Set rsSearch = New ADODB.Recordset
    15. rsSearch.CursorLocation = adUseClient
    16. Set rsSearch = cn.Execute(strSQL)
    17. Set rsSearch.ActiveConnection = Nothing
    18. cn.Close
    19. Set GetRecordset = rsSearch
    20. End Function
    21.  
    22. Private Sub LoadTheGrid(ByVal strSQL As String)
    23. Dim rs As ADODB.Recordset
    24. Dim iCol As Integer, iRow As Integer
    25. Dim fld As ADODB.Field
    26. Set rs = GetRecordset(strSQL)
    27. iRow = 0
    28. Me.MSFlexGrid1.Rows = rs.RecordCount
    29. If rs.RecordCount = 0 Then
    30. MsgBox ("No records meet your search query.")
    31. End If
    32. Me.MSFlexGrid1.Cols = rs.Fields.Count
    33. Do Until rs.EOF
    34. iCol = 0
    35. For Each fld In rs.Fields
    36. Me.MSFlexGrid1.TextMatrix(iRow, iCol) = fld.Value
    37. iCol = iCol + 1
    38. Next fld
    39. iRow = iRow + 1
    40. rs.MoveNext
    41. Loop
    42. End Sub
    43.  
    44. Private Sub CmdBack_Click()
    45. frmEditAsbestos.Show
    46. Form5.Hide
    47. End Sub
    48.  
    49. Private Sub CmdSearch_Click()
    50. Dim strSQL As String, strWhere As String
    51. strSQL = "SELECT * FROM Asbestos"
    52. If Text1.Text <> vbNullString Then
    53.     strWhere = strWhere & " AND [Sample Number] LIKE """ & Text1.Text & "%"""
    54. End If
    55. If Text2.Text <> vbNullString Then
    56.     strWhere = strWhere & " AND [Unit Number] LIKE """ & Text2.Text & "%"""
    57. End If
    58. If Text3.Text <> vbNullString Then
    59.     strWhere = strWhere & " AND [Product Type] LIKE """ & Text3.Text & "%"""
    60. End If
    61. If Text4.Text <> vbNullString Then
    62.     strWhere = strWhere & " AND [Asbestos Type] LIKE """ & Text4.Text & "%"""
    63. End If
    64. If Text5.Text <> vbNullString Then
    65.     strWhere = strWhere & " AND [Location In Unit] LIKE """ & Text5.Text & "%"""
    66. End If
    67. If Text6.Text <> vbNullString Then
    68.     strWhere = strWhere & " AND [PBC Job Number] LIKE """ & Text6.Text & "%"""
    69. End If
    70. If Text7.Text <> vbNullString Then
    71.     strWhere = strWhere & " AND [Work Done] LIKE """ & Text7.Text & "%"""
    72. End If
    73. If Text8.Text <> vbNullString Then
    74.     strWhere = strWhere & " AND [Date Of Completion] LIKE """ & Text8.Text & "%"""
    75. End If
    76. If Text9.Text <> vbNullString Then
    77.     strWhere = strWhere & " AND [Air Test Certificate Number] LIKE """ & Text9.Text & "%"""
    78. End If
    79. If Text10.Text <> vbNullString Then
    80.     strWhere = strWhere & " AND [Assessment Score - Material] LIKE """ & Text10.Text & "%"""
    81. End If
    82. If Text11.Text <> vbNullString Then
    83.     strWhere = strWhere & " AND [Assessment Score - Priority] LIKE """ & Text11.Text & "%"""
    84. End If
    85. If Text12.Text <> vbNullString Then
    86.     strWhere = strWhere & " AND [Assessment Score - Total] LIKE """ & Text12.Text & "%"""
    87. End If
    88. If strWhere <> vbNullString Then
    89.     strSQL = strSQL & " WHERE " & Mid$(strWhere, 5)
    90. End If
    91. LoadTheGrid (strSQL)
    92. End Sub
    93.  
    94. Private Sub Form5_Unload(Cancel As Integer)
    95. rsSearch.Close
    96. cn.Close
    97. Set rsSearch = Nothing
    98. Set cn = Nothing
    99. End Sub
    Last edited by hscott; Apr 12th, 2005 at 05:31 AM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width