+ Reply to Thread
Results 1 to 2 of 2

Using a table to keep Query arguments

Hybrid View

  1. #1
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Using a table to keep Query arguments

    Hi

    I am kind of a novice in Access, so hopefully this question makes sense.

    I want to build a Query that will pull certain fields from two different tables. To make it easy for an end user to decide which fields from each table to take, I'd like to create a table that holds each Query argument in it (tbl_Query_Holder). Then to add or take away an result from the Query, the user can simply remove that field from the tbl_Query_Holder via a form. I set up the tbl_Query_Holder to have 3 fields: Index, TableName, and FieldName. The TableName is the name of the table the Query will be pulling from, and the FieldName is the name of the field in that table to grab.

    My question is once I have tbl_Query_Holder populated, how do I generate a Query based on the info in it?

    Is this even possible? If not, is there a another way to accomplish what I am seeking to do?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Using a table to keep Query arguments

    Ok, I think I've found some basic code I can modify to do what I am looking for. This is what I'm working from:

    Public Sub CreateExportQuery()
    
    Dim CriteriaID As String
    Dim Record As String
    Dim Sample As Recordset
    Dim Test As String
    
    CriteriaID = ""
    Record = "SELECT * FROM tbl_Innovient_Input_Fields;"
    
    'Set Sample = CurrentDb.OpenRecordset(Record, dbOpenDynaset)
    'For a = 1 To Sample.RecordCount
    '    Test = Sample!Source_Field_Name
    'Next a
    
    Test = "SELECT * FROM"
    
    Set Sample = CurrentDb.OpenRecordset("tbl_Innovient_Input_Fields", dbOpenTable)
    For a = 1 To Sample.RecordCount
        Test = Test & " " & Sample!Source_Table_Name & "!" & Sample!Source_Field_Name
        Sample.MoveNext
    Next a
    
    Debug.Print Test
    
    End Sub
    I have already done some modifying which might explain why some of the variables are unused.

    I would still like to know anyone's input as to whether this is a smart way to set up this db.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1