• ** 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)

Status
Not open for further replies.

ajetrumpet

Banned
Local time
Today, 16:22
Joined
Jun 22, 2007
Messages
5,640
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:
Code:
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"
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom