Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Default Value of Text Box to Query Result

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.

like image 964
muncherelli Avatar asked Jan 06 '13 21:01

muncherelli


People also ask

What is the default field of a text box?

Default value is 0. Placeholder text is a short description or hint that that describes the expected value of an input field. (For example, "Enter phone number xxx-xxx-xxxx"). The short hint is displayed in the input field before the user enters a value.

Which property is used in textbox to provide default value in a control?

The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box control to =Now() , the control displays the current date and time.


1 Answers

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.

Dlookup Default value

like image 104
Fionnuala Avatar answered Sep 22 '22 14:09

Fionnuala