Results 1 to 6 of 6
  1. #1
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65

    Queries


    I am not well versed, yet, in using SQL queries, but am able to setup and use some basic queries. My problem is this. I am running Access from Visual Basic and I use queries in the datasets that are built in VB for the tables I am using from Access. What I want to do is filter a table based on the first 5 characters in a field. I have a variable that contains the characters I want to filter on. I have been looking through a lot of SQL query information but have, to date, been unable to find what I need. Can anyone here assist me with this?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you want to use a dynamic parameterized query and filter on a text field, try LIKE with wildcard. Review http://datapigtechnologies.com/flash...tomfilter.html

    I never use them and prefer http://www.allenbrowne.com/ser-62.html
    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.

  3. #3
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65
    It appears to me, June7, that you are telling me that the fact that I am wanting to filter on the first 5 characters, of a 9 character field is done simply by querying with those 5 characters that I input with a wildcard added to take into account the rest of the field. Anyway, that is what I get out of it. Thanks. I have not looked at your #2 approach yet, but will shortly. By the way, your first approach made me realize how to do something I had forgotten how to do, and that is how to show more than one field in a combobox and how to define which is the value item. Now I intend to figure out if I can do the same thing with VB.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Your criteria input would be just the 5 characters. The wildcard is in the query design.

    SELECT * FROM table WHERE [field name] LIKE [input 5 characters] & "*";
    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.

  5. #5
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65
    That is what I was trying to say. Obviously very poorly. When I first started to consider this I was thinking that I had to account for the fact that the field has 9 characters. Actually though, I can now see that by using the wildcard I do account for the fact that the field has 9 characters. Cool to know the answer is fairly easy........ this time.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    LIKE operator and wildcard works only for text type fields.
    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: 9
    Last Post: 08-27-2014, 11:34 AM
  2. Help with Queries
    By Sunwers in forum Queries
    Replies: 4
    Last Post: 07-15-2014, 08:12 AM
  3. Replies: 6
    Last Post: 11-13-2013, 04:17 PM
  4. Sub Queries
    By waqas in forum Queries
    Replies: 5
    Last Post: 01-24-2012, 11:48 AM
  5. Value from 2 queries
    By kwooten in forum Reports
    Replies: 1
    Last Post: 10-19-2011, 01:23 PM

Tags for this Thread

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