Results 1 to 3 of 3
  1. #1
    MSG56 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    29

    Can you dynamically select the "show" box in a query?

    I've got a search form with several different fields that the user may use to narrow down their search. If they only decide to search on one field I don't want the subsequent query to display all of the fields, but just the ones selected by the user. In other words, how can I modify which “show” boxes are selected in the query when I hit the “search” button on my form?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    On the form, put a list box of the possible fields they can pick. (multi-pick)
    scan the list, as you go, build the sql

    Code:
    dim sSql as string
    dim qdf as querydef
    
    for i = 0 to lstFlds.listcount - 1
        if lstFlds.item(i).selected then
        sSql = sSql & "[" & lstFlds.item(i) & "],"
    next
    
    'remove the last comma
    sSql = left(sSql, len(sSql)-1)
    
    sSql = "Select " & sSql & " from table"
    set qdf = currentdb.querydefs("qsCustom")
    qdf.sql = ssql
    qdf.close
    
    docmd.openquery qdf.name
    
    set qdf = nothing
    Last edited by ranman256; 10-10-2014 at 11:40 AM.

  3. #3
    MSG56 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    29
    Thanks for the quick response and advice. This is a lot for me to swallow. I'll have to take it a step at a time to figure it all out, but that will have to wait until at least Tue.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-20-2013, 05:14 PM
  2. Replies: 1
    Last Post: 08-12-2013, 09:34 AM
  3. Replies: 3
    Last Post: 04-10-2013, 01:20 PM
  4. Replies: 1
    Last Post: 10-08-2012, 09:01 AM
  5. Replies: 3
    Last Post: 07-23-2011, 09:12 AM

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