Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103

    Unanswered: Changing Tables in a Select Query

    Is there a way to select/specify the table to be used in a select query from a combo box on a form? For example, I have a combo box that displays the existing database objects - tables (2006_13, 2006_14, 2006_15, etc.) and I'd like the user to be able to run a select query that returns all values in the table they previoulsy selected from the combo box (2006_13).

    The selected table name (2006_13, 2006_14, 2006_15, etc.) exists in the form control and also in a make table that's created when the user makes their selection.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You'll need to do it in VBA:

    strSQL = "SELECT Blah FROM " & Me.ComboName & " WHERE..."

    I'm curious to know what the different tables contain, as it sort of smells like a normalization issue.
    Paul

  3. #3
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103
    Payroll data to be exact - for various pay periods.

    Would this statement be in the form of a DoCmd or part of the actual select query?

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Depends on what you want to do, but it must be built in VBA. You can't have that in the query itself. You could use QueryDef to set the SQL of a saved query to that, or set the source of a subform to it, or whatever.

    However, I have to say I don't like the design. Typically payroll data would be stored in one table, with specific pay period data either drawn out based on dates or via a field that specified which pay period it was for. What do you do when you want the data for a month, quarter, year or whatever?
    Paul

  5. #5
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103
    I may need to re-think my design. Thanks for your insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •