ajetrumpet
Banned
- Local time
- Yesterday, 22:37
- Joined
- Jun 22, 2007
- Messages
- 5,638
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:
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"