将文本框的默认值设置为查询结果

将文本框的默认值设置为查询结果

本文介绍了将文本框的默认值设置为查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简单的问题.我有一个形式的文本字段,我希望将默认值设置为查询结果.此特定查询返回我在Access中设置的小型发票系统的默认税率.

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.

查询(qrySettingsDefaultTaxRate)看起来像这样,并返回一行,该行包含我想设置为默认格式的税率的十进制等值:

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]

但是那没用.当我返回到窗体视图时,该框会显示" #Name?"作为默认值,而不是返回查询结果.

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.

推荐答案

您可以将文本框的控件源设置为 DLookup ,或在代码中将其值设置为DLookup.

You can set the control source of a textbox to DLookup, or set the value to DLookup in code.

DlookUp("default_tax_rate","qrySettingsDefaultTaxRate")

DlookUp("default_tax_rate","settings","settings.key_name='default_tax_rate'")

您甚至可以将DLookUp放在属性表的默认值"下.

You can even put DLookUp on the property sheet under Default Value.

这篇关于将文本框的默认值设置为查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:12