While you can't change the background color, I've come up with a solution that effectively allows you to change the background color.
First, I've created a new form called "background" that is completely empty, very large (large enough to fill the screen of your largest monitor), and has a dark gray background. It is not modal or popup, it auto resizes and centers, fits to screen, has no borders, record selectors, navigation buttons, dividing lines, scroll bars, control button, close button, or min max button, and it is not movable. All it has a little bit of VBA in its On Got Focus property:
-
Private Sub Form_GotFocus()
-
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Set db = CurrentDb
-
Set rst = db.OpenRecordset("SELECT ID, FormName, FrmRpt FROM FormStack ORDER BY ID", dbOpenSnapshot)
-
If rst.EOF Then
-
DoCmd.OpenForm "frmMenu"
-
Else
-
While Not rst.EOF
-
If rst.Fields("FrmRpt") = "Form" Then
-
If FormIsOpen(rst.Fields("FormName")) Then
-
Forms(rst.Fields("FormName")).SetFocus
-
Else
-
Call CloseFormStack(rst.Fields("FormName"))
-
End If
-
Else
-
If ReportIsOpen(rst.Fields("FormName")) Then
-
DoCmd.SelectObject acReport, rst.Fields("FormName")
-
Else
-
Call CloseFormStack(rst.Fields("FormName"))
-
End If
-
End If
-
rst.MoveNext
-
Wend
-
End If
-
rst.Close
-
Set rst = Nothing
-
End Sub
-
NOTE: the line
will open my menu form if no other form or report is open. Doing this is of course optional and you would want to change the name of the form that it opens.
I also created a table named "FormStack" that has the following fields:
ID (long integer, primary key)
FormName (short text)
FrmRpt (short text)
As for the other code which is saved in a separate module:
-
Public Sub FormStack(fName As String, frmrpt As String)
-
Dim sSQL As String
-
sSQL = "DELETE * FROM [FormStack] WHERE [FormName] = '" & fName & "'"
-
DoCmd.RunSQL (sSQL)
-
Dim Temp As Integer
-
Temp = 1
-
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Set db = CurrentDb
-
Set rst = db.OpenRecordset("SELECT [ID], [FormName] FROM [FormStack] ORDER BY [ID]", dbOpenSnapshot)
-
With rst
-
While Not .EOF
-
Temp = ![id] + 1
-
.MoveNext
-
Wend
-
End With
-
rst.Close
-
Set rst = Nothing
-
sSQL = "INSERT INTO [FormStack] ([ID], [FormName], [FrmRpt]) VALUES (" & Temp & ", '" & fName & "', '" & frmrpt & "')"
-
DoCmd.RunSQL (sSQL)
-
End Sub
-
-
Public Sub CloseFormStack(fName As String)
-
Dim sSQL As String
-
sSQL = "DELETE * FROM [FormStack] WHERE [FormName] = '" & fName & "'"
-
DoCmd.RunSQL (sSQL)
-
End Sub
-
-
Public Function FormIsOpen(strForm As String) As Boolean
-
Dim a As String
-
Dim Frm As Form
-
-
On Error GoTo ErrHandler
-
-
Set Frm = Forms(strForm)
-
a = Frm.Caption
-
-
FormIsOpen = True
-
-
FormIsOpenExit:
-
Exit Function
-
-
ErrHandler:
-
FormIsOpen = False
-
Resume FormIsOpenExit
-
-
End Function
-
After this you need to insert the following code into every forms (but NOT subforms) Activate, On Open and On Close events:
-
Private Sub Form_Activate()
-
Call FormStack("frmName", "Form")
-
End Sub
-
-
Private Sub Form_Close()
-
Call CloseFormStack("frmName")
-
End Sub
-
-
Private Sub Form_Open(Cancel As Integer)
-
Call FormStack("frmName", "Form")
-
End Sub
-
And for reports (but NOT subreports) this code:
-
Private Sub Report_Activate()
-
Call FormStack("rptName", "Report")
-
End Sub
-
-
Private Sub Report_Close()
-
Call CloseFormStack("rptName")
-
End Sub
-
-
Private Sub Report_Open(Cancel As Integer)
-
Call FormStack("rptName", "Report")
-
End Sub
-
Of course you can still have other code in these events as well. And you will have to put in the correct name of each form or report.
What all this code will do is ensure that your forms and reports are always on top of the background form. Should you ever accidentally click the background form, it will restore focus to every open form or report in the appropriate order (in other words, you are effectively sending the background to the back).
Now this isn't without a few problems. First, this code will not work with tables or queries. If a table or query is open and you click on the background, they will wind up forever beneath the background, the only way to get it back is to open it from the Navigation Pane again. I consider this a minor problem as your end users should only be working with forms and reports, but it is a bit of a pain for a developer. The other problem is that you want the background to cover the entire background, and you don't know how large the end users monitor will be, so it is wise to make the background form excessively large. While scroll bars will be disabled on the background form, they are not disabled in Access itself, and since the background is larger than the access window, you will wind up with scroll bars in your access window. Luckily your scroll wheel on your mouse does not effect these scroll bars, and I've had no one complain about to me in the month that we have been using the application so this too I consider a minor issue.