Fairly simple question. I have a text field in a form that I would like the default value to be set to the result of a query. This particular query returns a default tax rate for a small invoicing system I am setting up in Access.
The query (qrySettingsDefaultTaxRate) looks like this and returns one row with the decimal equivalent of the tax rate I would like to set as the default in this form:
SELECT CDbl([value]) AS default_tax_rate
FROM settings
WHERE (((settings.key_name)="default_tax_rate"));
I have tried setting the default value of my text field to:
=[qrySettingsDefaultTaxRate]![default_tax_rate]
However that didn't work. When I return to form view, the box comes up with "#Name?" as the default value instead of returning the result of the query.
You can set the control source of a textbox to DLookup, or set the value to DLookup in code.
DlookUp("default_tax_rate","qrySettingsDefaultTaxRate")
Or
DlookUp("default_tax_rate","settings","settings.key_name='default_tax_rate'")
You can even put DLookUp on the property sheet under Default Value.