Results 1 to 5 of 5
  1. #1
    rbordonaro is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    2

    Search for Text in Form

    Hi, I have spent hours trying to find an answer on google, entering code, using unbound text boxes with combo box, but it is just not working. I have an employee database, with about 3000 records. I have a field named Employee Name and a second existing field (not displayed in form) named Last Name. I want the user to be able to search by Last Name to see results for any one with that last name or it could be LIKE Employee Name.



    Second, I want to add a second text box search to enter a Job Code and get all the employees with that job code.

    So, the user can either enter Last Name or Job Code.

    I hope this is clear and I appreciate any help. It seems like such a simple task, but I just cannot get it.

    Again, thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    use a continuous form to show all records,
    then when the user fills in the boxes, then clicks the FIND button, use vb to build the where clause:

    Code:
    sub btnFind_click()
    dim sWhere as string
    
    if not IsNull(txtCode) then sWhere = sWhere & " and [JobCode]='" & me.txtCode & "'"
    if not IsNull(txtName) then sWhere = sWhere & " and [LastName] like '*" & me.txtName & "*'"
    
    if sWhere = "" then
       me.filterOn = false
    else
        sWhere = mid(sWhere,5)       'remove the 1st 'and'
       me.filter = sWhere
       me.filterOn = true
    endif
    end sub

  3. #3
    rbordonaro is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    2
    Thank you for the reply - I do appreciate it. Your reply is confusing to me. I am new to access - can you put in layman terms. How do I link the find button to the continuous form fields? I cannot click in the field names to change to a different last name.

    I am sorry....

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    The button is one you put on the form. Name it whatever you want. This is an example.
    the field names too. Use YOUR field names.

    put the code in the button click event.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Search with Text Box for Next Record on a Form (VBA)
    By nickmit11 in forum Programming
    Replies: 2
    Last Post: 07-18-2016, 12:43 PM
  2. Replies: 1
    Last Post: 04-09-2015, 05:13 PM
  3. Replies: 3
    Last Post: 09-02-2013, 04:33 PM
  4. Replies: 1
    Last Post: 04-20-2012, 03:16 AM
  5. Refresh form search text box
    By oxicottin in forum Forms
    Replies: 2
    Last Post: 11-19-2007, 02:28 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