Results 1 to 2 of 2
  1. #1
    lyndonguitar is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    1

    Question Help me in my search code

    Hi, I'm new here. I made a program for my mother for our business few years ago.(I self-studied a little bit of access) so far it has worked until recently.



    Now she tells me it got a problem on searches, She typed some of the entries(it has thousands of entries) with multiple spaces in between. so if shes searching that item "word*single space*word", it would not show up because it was written as "word*multiple spaces*word"

    I need it to be able to search for words that are separated by spaces individually, instead of searching everything in the text field as a whole. I forgot all about the codes and stuff so I need help please guys.

    My current code, I dunno what to do
    Code:
    Private Sub cmdSearch_Click()
    
    If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
    MsgBox "You must select a field to search."
    
    ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
    MsgBox "You must enter a search string."
    
    Else
    
    'Generate search criteria
    GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
    
    'Filter frmCustomers based on search criteria
    Form_frmAsperMold.RecordSource = "select * from AsperMold where " & GCriteria
    Form_frmAsperMold.Caption = "AsperMold (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
    
    'Close frmSearch
    DoCmd.Close acForm, "frmSearch"
    
    MsgBox "Results have been filtered."
    
    End If
    
    End Sub
    edit: i think i posted in the wrong section sorry

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Consistency in pattern is essential to search operations. Unless the number of spaces between words can be counted on to always be the same, there is no consistency. So if there is no reliable consistency in use of space character I suggest you clean up the data. This would involve repetitive UPDATE actions on the field using Replace() function. What do you suppose is the maximum number of consecutive spaces ever used - 5, 4, 3, 2? Do a Replace() UPDATE on each, starting with the highest.

    UPDATE tablename SET fieldname = Replace([fieldname], "imagine 5 spaces here", " ")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 12:34 PM
  2. Search for a String in VBA code.
    By dandoescode in forum Access
    Replies: 3
    Last Post: 06-21-2012, 11:00 AM
  3. VBA search code
    By Duncan in forum Access
    Replies: 6
    Last Post: 04-07-2012, 11:30 PM
  4. Msgbox And Search Code Not Working Properly
    By vampyr07au in forum Forms
    Replies: 1
    Last Post: 05-02-2011, 05:16 PM
  5. !!!!Urgent!!!! Search code doesn't work!
    By Laetilae in forum Programming
    Replies: 4
    Last Post: 12-13-2010, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums