Asked by:
1._Access. Cannot find why I am unable to set cmdButton.PressedColor = varColor1 and cmdButton1.PressedForeColor = varColor2

Question
-
Any ideas on this? Thanks for any help anyone can give me on this.
- Cannot find why I am unable to set cmdButton.PressedColor = varColor1 and cmdButton1.PressedForeColor = varColor2
Dim varColor1 as Variant
Dim varColor2 as Variant Both hold a Long value, or results of RGB(r,b,g) function.
Access 2013 VBA 7.1 64bit win 7
I am using this code.
in the form that calls code below has line.
Public abc As New clsFontsAndColorsOnly (holds Long number for colors, Integers for font size, string for font name)Private Sub WalkAllForms()
Dim frm as Form Dim x as Integer Dim intOpenFormCount as Integer
intOpenFormCount = Application.Forms.Count
Msgbox “ frm count = “ & intOpenFormCount
If intOpenFormCount = 0 Then
Msgbox “No Open Forms!”
Exit Sub
End If
For x = 0 To intOpenFormCount – 1
Debug.Print “Name = “ & Application.Forms(x).Name
Set frm = Application.forms(i)
SetCtls frm
Next x
End Sub
Private Sub SetCtls (frm as Form)
Dim ctl as Control
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acComboBox 'THIS WORKS GREAT.
.SetFocus
.BackColor = abc.cboCboBackColor 'abc' is a class module, that only holds in this case a Long Number.
.FontName = abc.HeadingFont 'this holds a string.Case acCommandButton 'COULD NOT GET REST OF THIS TO WORK TO CHANGE "PRESSED COLOR"
.SetFocus
‘I was unable to get to PressedColor. I double checked like this.
Me.cmdCloseAllFrms.PressedColor = vbGreen
‘And that worked.
'several other cases for the Select Case block, others worked.
End Select
End with
Next ctl
End Sub
- Also Unable to find why cannot set BackColor of form’s detail section. in Private Sub SetCtls (frm as Form)
I Used
Me.Section(acDetail).BackColor = varColor3
Mark J
Friday, July 7, 2017 3:51 AM
All replies
-
> 'several other cases for the Select Case block, others worked.
Hi Mark, you need to use PRECISE language and be explicit about what does or does not work, how you get to that conclusion, and what if any error messages you are getting. As it stands all we have is "I programmatically set the PressedColor to some value, and I'm having unspecified errors".
Did you use the debugger to step through and ensure the code is taking the branches you expected and the variables have the values you expected?
-Tom. Microsoft Access MVP
Friday, July 7, 2017 4:22 AM -
.BackColor = abc.cboCboBackColor 'abc' is a class module, that only holds in this case a Long Number. .FontName = abc.HeadingFont 'this holds a string.
did you try to set the value of 'abc.cboCboBackColor'?
where you set it.
you had mentioned that abc is class module.
if had set its value then make sure that you set it correctly.
try to print it in immediate window.
if you did not set it then try to refer code below to set the it value.
' Create the object from the class module Dim oCustomer As New clsCustomer ' Set the customer name oCustomer.Name = "John" ' Print the name to the Immediate Window(Ctrl + G) Debug.Print oCustomer.Name
from your code it looks like you are not getting the value from the class module.
if you are just storing the value then try to store the value on current normal module.
is there any special requirement to store value in class module?
if yes then refer the code example I posted above to set the value and let me know about the result.
Regards
Deepak
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Friday, July 7, 2017 10:02 AM -
Hi Mark,
>> COULD NOT GET REST OF THIS TO WORK TO CHANGE "PRESSED COLOR"
How did you check whether this code “cmdButton.PressedColor = varColor1” works? In my option, PressedColor for cmdButton could be visible only when you click the button.
For example, I add two command buttons on a form and add below code to one of them, after clicking Command26, it will set PressedColor for Command27, then when you press the Command27, you will find the Command27 change to Green.
Private Sub Command26_Click() Me.Command27.PressedColor = vbGreen End Sub
Best Regards,
Edward
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, July 13, 2017 8:52 AM -
For x = 0 To intOpenFormCount – 1
Debug.Print “Name = “ & Application.Forms(x).Name
Set frm = Application.forms(i)
SetCtls frm
Next x
Hi Mark,
Your running variable is "x", nevertheless you use "i" in Set frm = Application.Forms(i)
You should have had a compile error because the variable "i" was not declared.
With no compile errors you better start any module with the line: Option Explicit
Imb.
Thursday, July 13, 2017 10:01 AM -
Imb-hb,
Sorry about that. I would have sworn that I included sub that walks thru all forms.
and sub that changes controls. I is used in one sub X in another sub.
Private Sub WalkAllForms()
Dim frm As Form
Dim i As Integer
Dim intOpenFormCount As Integer
intOpenFormCount = Application.Forms.CountMsgBox " frm count = " & intOpenFormCount
If intOpenFormCount = 0 Then
MsgBox "No open forms"
Exit Sub
End IfFor i = 0 To intOpenFormCount - 1
Debug.Print "Form names using Application.Forms(i)=" & Application.Forms(i).Name
MsgBox "name = " & Application.Forms(i).Name
'works 7/24/16 9:28 am
'SetCtls (Application.Forms(i).Name) 'type missmatch 7/24/16 9:36 am
'If frm.Caption = Screen.ActiveForm.Caption Then
' MsgBox "active form here is " & frm.Caption
'End If
Set frm = Application.Forms(i)
SetCtls frm 'WORKS 7/28/16 4:19 PM this line calls sub to change controls.
Next iEnd Sub
Also
Private Sub WalkAllForms()
Dim frm As Form
Dim i As Integer
Dim intOpenFormCount As Integer
intOpenFormCount = Application.Forms.CountMsgBox " frm count = " & intOpenFormCount
If intOpenFormCount = 0 Then
MsgBox "No open forms"
Exit Sub
End IfFor i = 0 To intOpenFormCount - 1
Debug.Print "Form names using Application.Forms(i)=" & Application.Forms(i).Name
MsgBox "name = " & Application.Forms(i).Name
'works 7/24/16 9:28 am
'SetCtls (Application.Forms(i).Name) 'type missmatch 7/24/16 9:36 am
'If frm.Caption = Screen.ActiveForm.Caption Then
' MsgBox "active form here is " & frm.Caption
'End If
Set frm = Application.Forms(i)
SetCtls frm 'WORKS 7/28/16 4:19 PM
Next iEnd Sub
Also "SetCtls" is a Sub listed below.
Private Sub SetCtls(frm As Form)
' use in forms like this Call SetCtls Me 'seems do not need "call"
'THIS IS in form "frmStart"
'Debug.Print Me!Form.Name
Dim ctl As ControlFor Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acComboBox 'all this works.
.SetFocus
.BackColor = abc.cboCboBackColor
.FontName = abc.HeadingFont
Case acCommandButton
.SetFocus
.BackColor = abc.CmdColorPressed
MsgBox "cmdButton color pressed = " & abc.CmdColorPressed
Case acDetail 'does not work
.SetFocus
' .BackColor = abc.FrmDetailColor
Debug.Print "abc.frmdetailcolor = " & abc.FrmDetailColor
Me.Section(acDetail).BackColor = abc.FrmDetailColor
' MsgBox "detail " & Me.Name
Case acLabel 'all works
'.SetFocus
.BackColor = abc.LabelInfoBackColor
.ForeColor = abc.LabelFontColor
Case acToggleButton 'all works
.SetFocus
.BackColor = abc.cmdColorUnPressed
.ForeColor = abc.LabelFontColor
Case Else
MsgBox "SHOULD NOT BR POSSIBLE TO GET HERE!!! Control type must NOT be listed!", vbExclamation
MsgBox "Control Type to get here is " & .ControlType
'Seems getting #106 that was CheckBox, and could not change colors. Seems only colors could
'change was the lines of the box. Could not find way to make lines thick enought to notice diff
'in color.
End SelectEnd With
Next ctl
End Sub
hope this explains why no compile errors do to "I" and "x"
again sorry I goofed in not showing both Sub routines.
Mark j
Mark J
Tuesday, July 18, 2017 8:15 AM -
as I mentioned before, did you try to check the value that you are accessing from class?
let us know about that so that we can know that it is correct or not.
if you are not able to access the value then try to set the value like I show you before.
also you can show us how you set it in your code.
in your select case , you had mentioned that some case are working and some case are not working.
I suggest you to test the that part of code separately and check that the code you want to execute it is supported by that part of the form or control and your code is executing that part of case when you run the code.
it will help you to find the issue.
Regards
Deepak
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Tuesday, July 18, 2017 9:48 AM