ajetrumpet
04-06-2010, 02:08 PM
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 'ALTERNATIVE CODING
db.CreateQueryDef "your query name", _
"SELECT [" & Forms!formname!TXTfld & "] FROM " & forms!formname!TXTtbl
RefreshDatabaseWindow 'ALTERNATIVE CODING
DoCmd.OpenQuery "your query name"
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 'ALTERNATIVE CODING
db.CreateQueryDef "your query name", _
"SELECT [" & Forms!formname!TXTfld & "] FROM " & forms!formname!TXTtbl
RefreshDatabaseWindow 'ALTERNATIVE CODING
DoCmd.OpenQuery "your query name"