如何动态设置所有申请表标题属性

发布于 2024-10-13 01:01:47 字数 553 浏览 9 评论 0原文

我有一个 Access 应用程序,可以访问 3 个环境(DEV;TEST;PROD)。登录时设置环境变量,以便以编程方式连接到正确的数据库。

我们希望用户能够看到他们使用的每种形式连接到哪个环境。一种想法是设置标题栏的颜色,但这会影响所有窗口。

我一直在尝试使用环境变量将环境动态地放入表单标题中。

在表单属性中设置事件过程,例如“当前”或“打开”,例如:

Me.Caption = Me.Caption & ” : “ & Me!txtEnvName.Value

.... 在登录应用程序时的动态过程中是我想做的。

手动更改应用程序中的所有表单并不是理想的选择。

以下是表单在 3 种不同环境中的外观示例:

  Customers: DEV

//////////

  Customers: TEST

/////////

  Customers: PRODUCTION

I have one Access application which accesses 3 environments (DEV; TEST; PROD). An environment variable is set upon login to programmatically connect to the correct database.

We would like the user to see which environment they are connected to in each form they use. One thought is to set the color of the title bar, but that impacts all windows.

I have been attempting to put the environment in the form caption dynamically by using the environment variable.

Setting an Event Procedure in the Form Properties such as On Current or On Open such as:

Me.Caption = Me.Caption & " : " & Me!txtEnvName.Value

.... in a dynamic process upon signin to the application is what I would like to do.

Manually changing all the forms in the application is not a desired option.

Here is a sample of what a form would look like in the 3 different evironments:

  Customers: DEV

//////////

  Customers: TEST

/////////

  Customers: PRODUCTION

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野却迷人 2024-10-20 01:01:47

您可以轻松地为所有表单设置标题:

Const strEnvironment = " : DEV"

Sub FormCaption()
Dim frm As Object
For Each frm In CurrentProject.AllForms
    DoCmd.OpenForm frm.Name, acDesign
    Forms(frm.Name).Caption = frm.Name & strEnvironment
    DoCmd.Close acForm, frm.Name, acSaveYes
Next

End Sub

但是,我建议您使用每个表单的 Open 事件来检查全局变量并相应地设置标题。

You can set the captions for all the forms easily enough:

Const strEnvironment = " : DEV"

Sub FormCaption()
Dim frm As Object
For Each frm In CurrentProject.AllForms
    DoCmd.OpenForm frm.Name, acDesign
    Forms(frm.Name).Caption = frm.Name & strEnvironment
    DoCmd.Close acForm, frm.Name, acSaveYes
Next

End Sub

However, I suggest you use the Open event of each of the forms to check a global variable and set the caption accordingly.

墟烟 2024-10-20 01:01:47

这会将 COMPUTERNAME 环境变量添加到我的表单的标题中。

Private Sub Form_Open(Cancel As Integer)
    Me.Caption = Me.Caption & ": " & Environ("COMPUTERNAME")
End Sub

如果您还想使用颜色来区分数据库实例,则可以更改详细信息部分的背景颜色。这将根据 Your_env_variable 的值更改它。

Dim lngColor As Long
Select Case Your_env_variable
Case "DEV"
    lngColor = vbRed
Case "TEST"
    lngColor = vbYellow
Case "PRODUCTION"
    lngColor = vbGreen
Case Else
    lngColor = -2147483633
End Select
Me.Detail.BackColor = lngColor

This adds the COMPUTERNAME environment variable to the Caption of my form.

Private Sub Form_Open(Cancel As Integer)
    Me.Caption = Me.Caption & ": " & Environ("COMPUTERNAME")
End Sub

If you want to also include color to distinguish between the database instances, you could change the detail section background color. This would change it based on the value of Your_env_variable.

Dim lngColor As Long
Select Case Your_env_variable
Case "DEV"
    lngColor = vbRed
Case "TEST"
    lngColor = vbYellow
Case "PRODUCTION"
    lngColor = vbGreen
Case Else
    lngColor = -2147483633
End Select
Me.Detail.BackColor = lngColor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文