0

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
DonC
  • 1
  • 1
  • 1
  • Can you have a Help/About form? – Beth Jan 19 '11 at 20:23
  • Your suggestion is an option, but not what the application manager wants to see. They want it to 'jump out' at the user. Thus the original thought of using different colors for the different envirionments. The fear of testing in production is the worry here. The Help/About would require the user to think about what environment they are in in the first place. Not a bad idea as an extra help though. Thanks again. – DonC Jan 19 '11 at 20:40
  • How about adding a form to dev and test environments, or add a caption to a splash screen? – Beth Jan 19 '11 at 20:45

2 Answers2

1

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.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
1

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
HansUp
  • 95,961
  • 11
  • 77
  • 135