在多个表单中放置相同的值 [英] Placing the Same Value In Multiple Forms

查看:72
本文介绍了在多个表单中放置相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用多个表单的Access 2K应用程序。我们

目前在每张表格的标签上硬编码发行号,但每次发布新版本时,这个

都会变得乏味。我认为这将很容易将新的版本号放在一个位置(一个表)中,并且每个表单中都有

表示文本框中的表/版本号我会为每个表单添加
,但显然,它并不像我预计的那样简单。非常感谢任何能够进一步了解的人。

谢谢Sheldon Potolsky

We have an Access 2K application that uses multiple forms. We
currently hardcode the release number in a label on each form but this
gets tedious to do each time there''s a new release. I thought it would
be easy to put the new release number in one spot (a table) and have
each form reference that table/release number in a text box that I
would add to each form but, apparently, it''s not as simple as I
expected it to be. Would appreciate anyone who could shed further
light on how to do this.
Thank you, Sheldon Potolsky

推荐答案

< SH ******** @ aol.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
<SH********@aol.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
我们有一个使用多个表单的Access 2K应用程序。我们目前对每个表单上的标签中的版本号进行硬编码,但每次发布新版本时,这都很繁琐。我认为将新的版本号放在一个位置(一个表格)并且每个表单引用表格/版本号在我将添加的文本框中是很容易的。每种形式,但显然,它并不像我预期的那样简单。非常感谢能够进一步了解如何做到这一点的任何人。
谢谢Sheldon Potolsky
We have an Access 2K application that uses multiple forms. We
currently hardcode the release number in a label on each form but this
gets tedious to do each time there''s a new release. I thought it would
be easy to put the new release number in one spot (a table) and have
each form reference that table/release number in a text box that I
would add to each form but, apparently, it''s not as simple as I
expected it to be. Would appreciate anyone who could shed further
light on how to do this.
Thank you, Sheldon Potolsky



会有其他解决方案,但可能会更容易从使用

标签更改为文本框。如果你想更改标签的标题,你需要

来编写每种形式的代码。但是,对于texbox,您有一个

数据源属性,因此可以查找版本号。不要担心

关于文本框的外观 - 我们可以更改它以使其看起来像

标签。


创建一个新的代码模块,其中包含以下函数:


公共函数GetVersionNumber()As String

GetVersionNumber =" 1.01"

结束功能


编译并保存模块。接下来在表单上放置一个新文本框并删除

其关联标签。

Name = txtVersionNumber

特效=平面

后退风格=透明

启用=否

锁定=是

数据源是= GetVersionNumber()没有引号


现在您在一个表单上有文本框,只需将其复制并粘贴到您希望更新的后续表单中的每一个

。显然旧的标签应该被删除。


这种方法将版本号存储在代码中 - 它应该更快而且它是

使它远离非编码器可能碰到它的表格。如果你感觉

你必须将它存储在一个表中,那么你可以将文本框的数据源

设置为一个dlookup函数来提取它 - 但我会坚持我的建议。


There will be other solutions, but it might be easier to change from using a
label to a textbox. If you want to change the caption of a label you have
to write code in each of these forms. However, with a texbox, you have a
datasource property so the version number can be looked up. Don''t worry
about the look of a textbox - we can change that to make it look like a
label.

Create a new code module and in it palce the following function:

Public Function GetVersionNumber() As String
GetVersionNumber = "1.01"
End Function

Compile and save the module. Next place a new textbox on a form and delete
its associated label.
Name=txtVersionNumber
Special Effect=Flat
Back Style=Transparent
Enabled=No
Locked=Yes
Datasource is "=GetVersionNumber()" without the quotes

Now you have the textbox on one form, just copy and paste it on to each of
the subsequent forms you wish to update. Obviously the old labels should
just be deleted.

This approach stores the version number in code - it should be faster and it
keeps it away from the tables where non-coders might touch it. If you felt
you had to store it in a table, then you could set the textbox''s datasource
to a dlookup function to extract it - but I would stick with my suggestion.


是的,你可以按照你的说法去做。将版本号沿着

放在表格中,并附上生效日期。您甚至可以提前将它们放在桌子上。

。在表单的Load事件中,您可以指定标签的Caption

属性,或者您可以创建一个看起来像标签的文本框

并使其成为计算控件。如果你去文本框路线,你可能需要

来将文本框的Locked和Enabled属性设置为Yes。


然后查找公式be:

DLookup(" [ReleaseNumberField]",[TableName]"," [DateField] =

DMax("" [DateField ]"","" [TableName]"""" [DateField]< = Date()"")")


注意双引号,它们是因为你需要将引号传递给

嵌入式函数,而不要让外部函数认为它已经到达字符串的末尾。


另一种选择是使用查询而不是表。如果您按日期字段降序对

查询进行排序,则DLookup将停止在符合条件的
找到的第一条记录上。然后,您可以使用以下语句:


DLookup(" [ReleaseNumberField]",[QueryName]"," [DateField]< = Date()" ;)


-

Wayne Morgan

MS Access MVP

< SH ** ******@aol.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Yes, you can do as you state. Place the release number in the table along
with the date that it goes into effect. You can even place them in the table
ahead of time. In the Load event of the form you can assign the Caption
property of the label or you could create a textbox that looks like a label
and make it a calculated control. If you go the textbox route, you may want
to set the Locked and Enabled properties of the textbox to Yes.

The formula for the lookup would then be:
DLookup("[ReleaseNumberField]", "[TableName]", "[DateField] =
DMax(""[DateField]"", ""[TableName]"", ""[DateField]<=Date()"")")

Note the double quotes, they are because you need to pass quotes to the
embedded function without making the outer function think that it has
reached the end of its string.

Another option would be to use a query instead of the table. If you sort the
query descending on the date field, DLookup will stop at the first record it
finds that meets the criteria. You could then use the following statement:

DLookup("[ReleaseNumberField]", "[QueryName]", "[DateField]<=Date()")

--
Wayne Morgan
MS Access MVP
<SH********@aol.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
我们有一个使用多个表单的Access 2K应用程序。我们目前对每个表单上的标签中的版本号进行硬编码,但每次发布新版本时,这都很繁琐。我认为将新的版本号放在一个位置(一个表格)并且每个表单引用表格/版本号在我将添加的文本框中是很容易的。每种形式,但显然,它并不像我预期的那样简单。非常感谢任何能够进一步了解如何做到这一点的人。
谢谢Sheldon Potolsky
We have an Access 2K application that uses multiple forms. We
currently hardcode the release number in a label on each form but this
gets tedious to do each time there''s a new release. I thought it would
be easy to put the new release number in one spot (a table) and have
each form reference that table/release number in a text box that I
would add to each form but, apparently, it''s not as simple as I
expected it to be. Would appreciate anyone who could shed further
light on how to do this.
Thank you, Sheldon Potolsky



感谢您的建议。我走了文本框路线,确保

启用和锁定设置为是,仅使用版本号(没有

日期)并添加以下代码在表格激活和

成功 -

私人子Form_Activate()

昏暗的MyDB作为数据库

昏暗VarRS As Recordset

Dim strSQL As String

设置MyDB = CurrentDb

strSQL =" SELECT * FROM tblVersion;"

设置VarRS = MyDB.OpenRecordset(strSQL,dbOpenSnapshot)

VarRS.MoveFirst

Text2.Value = VarRS(" Version")

VarRS.Close

设置VarRS = Nothing

设置MyDB = Nothing

End Sub


Sheldon Potolsky

Thanks for the suggestions. I went the Text box route, ensured that
Enabled and Locked were set to "yes", only used the release number (no
date) and added the following code on the form activation and was
successful -
Private Sub Form_Activate()
Dim MyDB As Database
Dim VarRS As Recordset
Dim strSQL As String
Set MyDB = CurrentDb
strSQL = "SELECT * FROM tblVersion;"
Set VarRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
VarRS.MoveFirst
Text2.Value = VarRS("Version")
VarRS.Close
Set VarRS = Nothing
Set MyDB = Nothing
End Sub

Sheldon Potolsky


这篇关于在多个表单中放置相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆