• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Display query fields dynamically (1 Viewer)

Not open for further replies.


Local time
Today, 16:22
Jun 22, 2007
I just answered this question, and I'm sure it will come up again. If you want to specify fields to be displayed in a query, through the form interface, the only way I know how is to call a function from the form.

Assume a control named TXTfld shows the field name you want to display, and a control named TXTtbl shows the table name you want to query. The code then needs to be:
on error resume next

Dim db As Database
Set db = CurrentDb

db.QueryDefs.Delete "your query name"

RefreshDatabaseWindow [COLOR="DarkGreen"]'ALTERNATIVE CODING[/COLOR]

db.CreateQueryDef "your query name", _
                  "SELECT [" & Forms!formname!TXTfld & "] FROM " & forms!formname!TXTtbl

RefreshDatabaseWindow [COLOR="DarkGreen"]'ALTERNATIVE CODING[/COLOR]

DoCmd.OpenQuery "your query name"
Not open for further replies.

Users who are viewing this thread

Top Bottom