Results 1 to 4 of 4

Command for writing code for Search Command Button

  1. #1
    SSUTTON is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    24

    Command for writing code for Search Command Button


    Hi: I have been looking for VBA Code to make a search command button. Could anyone help with this please? Thank you. I only joined this site a few days ago and I have learned alot already. Thank you!

  2. #2
    Ajax is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    7,078
    A very broad question and the answer very much depends on what you are searching for and where and how you want to search. Assuming your button is on a form which has the recordset you want to search the principle is

    me.filter="searchcriteria"
    me.filteron=true

    to build your search criteria you might have

    searchcriteria="[customerName] like '*" & txtCustomerName & "*'"

    or

    searchcriteria="[Amount]=" & txtAmount

    where tctCustomerName and txtAmount are the names of unbound controls on your form

    to combine them you would have

    searchcriteria="[customerName] like '*" & txtCustomerName & "*' AND [Amount]=" & txtAmount

    Since you are new to this, to practice and experiment I would set up query in the query designer and set criteria to 'find' the records you want. When you have it working, look at the SQL view for what appears after the WHERE keyword - note the use of brackets and quotation marks, this will be how you need to construct your search criteria string

  3. #3
    SSUTTON is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    24
    Thank you!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    13,910

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

Similar Threads

  1. Replies: 1
    Last Post: 09-12-2014, 06:09 AM
  2. Quick VBA Command Button code help :)
    By noaccessguru in forum Forms
    Replies: 1
    Last Post: 10-01-2013, 08:35 PM
  3. Command Button VBA Code
    By nyymattingly23 in forum Programming
    Replies: 13
    Last Post: 01-04-2013, 03:08 PM
  4. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  5. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 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
  •  
Tech Forums: Microsoft Office Forums