grendell2099
Registered User.
- Local time
- Today, 06:52
- Joined
- Aug 9, 2006
- Messages
- 29
Hi all- I need some help with subforms and subform controls. I have been searching high and low without success.
What I am trying to do:
I am trying to make a procedure (in a module) that can be called from any form that will change the form backcolor, as well as the color of any text boxes & labels. I know how to do this.
However, I have some forms that have subforms on them and I have been unable to correctly reference the subforms or their controls to change the colors.I thought I could pass the name of the form on open to this module and loop through sub form controls if a sub form was present.
Why do I want to do this?
My application is distributed as an accde. The vast majority of my users prefer a bright form layout- lots of white. A few users would like a dark view.
I figured why not change the color scheme dynamically when a user opens the form. I have done some testing and there is no performance lag.
I suppose this falls into the category of doing it just to do it, but at the very least I hope to learn something. Below is my crack at the code- any help would be appreciated.
Sub ChangeFormColor(MyForm As String, MySub As String)
Dim frm As Form
Dim MyFormName As String
Dim ctl As Control
Dim MyView As String
Dim x
Dim Xname
'************************************
MyView = "DARK" 'test value
Select Case [MyForm]
Case Is = "frmBackup" 'skip this form
Case Else
Set frm = Forms(MyForm)
'--- CHANGE THE HEADER ---
If MyView = "DARK" Then
frm.Section(acHeader).BackColor = 16743697
frm.Section(acDetail).BackColor = 0
frm.Section(acDetail).AlternateBackColor = 0
Else
frm.Section(acHeader).BackColor = 3289650
frm.Section(acDetail).BackColor = 13754083
frm.Section(acDetail).AlternateBackColor = 13754083
End If
'--- NOW CHANGE THE HEADER CONTROLS ---
For Each ctl In frm.Section(acHeader).Controls
x = ctl.ControlType
Xname = ctl.Name
With ctl
If MyView = "Dark" Then
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
case acSubForm
'this is where I am stuck, I cannot figure out the syntax
' if there is a subform, change the header and detail color
'loop through subform controls and change their forecolor, bordercolor, and backstyle
Case acLabel
.BackStyle = 0
.ForeColor = 0
.BorderColor = 0
Case Else
.BackStyle = 1
.ForeColor = 0
.BorderColor = 0
End Select
End If
End With
Next
'--- CHANGE THE DETAIL CONTROLS ---
For Each ctl In frm.Section(acDetail).Controls
'+++++++++++++
x = ctl.ControlType
Xname = ctl.Name
'+++++++++++++
With ctl
If MyView = "Dark" Then
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
Case acSubform
Case acLabel
.BackStyle = 0
.ForeColor = 16743697
.BorderColor = 16743697
Case Else
.BackStyle = 1
.BackColor = 0
.ForeColor = 16743697
.BorderColor = 16743697
End Select
Else 'apply the light theme
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
Case acSubform
Case acLabel
.BackStyle = 0
.ForeColor = 16777215
.BorderColor = 2031743
Case Else
.BackStyle = 1
.ForeColor = 16777215
.BorderColor = 2031743
End Select
End If
End With
Next
End Select
'------------------------------------------------------------------------------------
End Sub
What I am trying to do:
I am trying to make a procedure (in a module) that can be called from any form that will change the form backcolor, as well as the color of any text boxes & labels. I know how to do this.
However, I have some forms that have subforms on them and I have been unable to correctly reference the subforms or their controls to change the colors.I thought I could pass the name of the form on open to this module and loop through sub form controls if a sub form was present.
Why do I want to do this?
My application is distributed as an accde. The vast majority of my users prefer a bright form layout- lots of white. A few users would like a dark view.
I figured why not change the color scheme dynamically when a user opens the form. I have done some testing and there is no performance lag.
I suppose this falls into the category of doing it just to do it, but at the very least I hope to learn something. Below is my crack at the code- any help would be appreciated.
Sub ChangeFormColor(MyForm As String, MySub As String)
Dim frm As Form
Dim MyFormName As String
Dim ctl As Control
Dim MyView As String
Dim x
Dim Xname
'************************************
MyView = "DARK" 'test value
Select Case [MyForm]
Case Is = "frmBackup" 'skip this form
Case Else
Set frm = Forms(MyForm)
'--- CHANGE THE HEADER ---
If MyView = "DARK" Then
frm.Section(acHeader).BackColor = 16743697
frm.Section(acDetail).BackColor = 0
frm.Section(acDetail).AlternateBackColor = 0
Else
frm.Section(acHeader).BackColor = 3289650
frm.Section(acDetail).BackColor = 13754083
frm.Section(acDetail).AlternateBackColor = 13754083
End If
'--- NOW CHANGE THE HEADER CONTROLS ---
For Each ctl In frm.Section(acHeader).Controls
x = ctl.ControlType
Xname = ctl.Name
With ctl
If MyView = "Dark" Then
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
case acSubForm
'this is where I am stuck, I cannot figure out the syntax
' if there is a subform, change the header and detail color
'loop through subform controls and change their forecolor, bordercolor, and backstyle
Case acLabel
.BackStyle = 0
.ForeColor = 0
.BorderColor = 0
Case Else
.BackStyle = 1
.ForeColor = 0
.BorderColor = 0
End Select
End If
End With
Next
'--- CHANGE THE DETAIL CONTROLS ---
For Each ctl In frm.Section(acDetail).Controls
'+++++++++++++
x = ctl.ControlType
Xname = ctl.Name
'+++++++++++++
With ctl
If MyView = "Dark" Then
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
Case acSubform
Case acLabel
.BackStyle = 0
.ForeColor = 16743697
.BorderColor = 16743697
Case Else
.BackStyle = 1
.BackColor = 0
.ForeColor = 16743697
.BorderColor = 16743697
End Select
Else 'apply the light theme
Select Case .ControlType
Case acCommandButton
Case acCheckBox
Case acTabCtl
Case acPage
Case acSubform
Case acLabel
.BackStyle = 0
.ForeColor = 16777215
.BorderColor = 2031743
Case Else
.BackStyle = 1
.ForeColor = 16777215
.BorderColor = 2031743
End Select
End If
End With
Next
End Select
'------------------------------------------------------------------------------------
End Sub