Results 1 to 6 of 6
  1. #1
    technesurge is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    14

    How do you select a field based on user input?

    I have many fields of data in a table. I want the user to type in the name of the field and use that in a query.



    For example, the table looks like this:

    DateAndTime, Field1, Field2, Field3, ... FieldX
    --------------------------------------------------
    6/20/2012 2:00PM, 14, 6, 45...
    6/20/2012 2:00PM, 8, 5, 13...
    6/20/2012 2:00PM, 53, 25, 62...

    If the user types in "Field1" (through a form or parameter)
    Then the query would select Field1:

    14
    8
    53


    I tried using a parameter in the SELECT statement and that did not work... any suggestions?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm curious what the fields contain, as I suspect a normalization issue. In any case, the only way to do what you describe would be to build the SQL in VBA code. I don't know of any way to dynamically select the fields in a query (because in a normalized database you wouldn't need to).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    technesurge is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    14
    Each field is a temperature transmitter.Each record occurs once per second. Somehow I need to create a way for the user to choose Transmitter X and then I will graph that data. I'm trying to avoid making a graph for each transmitter because there are many.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The normalized design would be

    Code:
    DateTime             TransmitterID   Reading
    6/20/2012 2:00PM         1             14
    6/20/2012 2:00PM         2              6
    Then your query is simple; the user chooses the transmitterID and perhaps a date/time range.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    technesurge is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    14
    Ok, I understand what you mean about renormalizing the data. I've been trying to put the data in the format you have prescribed with no success. Perhaps you could point in the right direction, thank you.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Perhaps if I knew exactly what you were trying and exactly what goes wrong. You can use a UNION query or a series of append queries to get the data from your original table to a normalized table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 01-15-2012, 02:46 PM
  2. Selecting records based on criteria from user input
    By shabbaranks in forum Programming
    Replies: 1
    Last Post: 01-04-2012, 09:06 AM
  3. display a list of values based on user input
    By karl1971 in forum Access
    Replies: 3
    Last Post: 12-06-2011, 09:19 AM
  4. Replies: 3
    Last Post: 08-25-2010, 09:03 AM
  5. Select a certain field of a record based on ID
    By cesarone82 in forum Access
    Replies: 3
    Last Post: 06-06-2009, 01:16 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