MS Access Toggle Button background - ms-access

Is it possible to totally remove the background color and the border of a toggle button in Access? As shown in the Imgur picture, I'd like to remove the grey-ish background and the border of the button totally so I'd keep the white icon (that list icon) only. Would that even be possible?

I am sure this is related to your other question at MS Access ToggleButton Picture change.
Use an Image control with embedded image and this code (note declaration of public variable in header):
Option Compare Database
Option Explicit
Public booMenu
Sub timeout(duration_ms As Double)
Dim Start_Time As Double
Start_Time = Timer
Do
DoEvents
Loop Until (Timer - Start_Time) >= duration_ms
End Sub
Private Sub Image5_Click()
Dim x As Integer
booMenu = Not booMenu
Me.Menu.Visible = True
Do
DoEvents
Me.Menu.Width = Me.Menu.Width + IIf(booMenu, 200, -200)
Me.Menu.Left = Me.Menu.Left - IIf(booMenu, 200, -200)
Me.Image5.Left = Me.Image5.Left - IIf(booMenu, 200, -200)
timeout (0.01)
x = x + 1
Loop Until x = 10
Me.Menu.Visible = booMenu
End Sub

I managed to find (kind of) a solution to this. The solution was to change the following parameters:
Use Theme = No;
BackColor = Form Color;
Pressed Back Color = Form Color
Eventually, it provides an effect very similar to the one that I was trying to achieve.

Related

How to short the code to change control properties on command buttion click in ms-access vba

I have a userform with a group of command buttons with similiar properties and fuctionality. I am using these buttons to let the user keep track about his activity. So e.g. whenever user will click the "production" button the application label will say "production" mode, when the user presses "Break" button the label will change from "production" mode to "Break" mode, Similiarly I have 7-8 buttons altogether on same form. Other conditions are whichever buttons gets pressed that button should get disabled and all other buttons should get enabled, followed by next button, if pressed it should get disabled and it should enable the button which was pressed previously.
The button which has been pressed whould also change its color and should also change the previous button's color back to normal.
I understand it would be difficult to understand the scenario, please check the code below for one of my buttons and its working well.
Private Sub btn1()
Me.Label78.Caption = Me.btn1.Caption
Me.btn1.BackColor = RGB(250, 100, 100)
Me.btn1.Gradient = 12
Me.btn1.Enabled = False
Me.btn2.Enabled = True
Me.btn2.BackColor = RGB(100, 250, 100)
Me.btn2.Gradient = 12
Me.btn3.Enabled = True
Me.btn3.BackColor = RGB(100, 250, 100)
Me.btn3.Gradient = 12
End Sub
the above code works perfeclty and changes properties to 3 buttons(its sample code not the code for all 7 buttons), but I have total 7-8 button and i may add more buttons in future SO if i keep on writing this kind of code in one button for all 7-8 buttons, then it will take a lot of time and efforct.
So what is the best possible way to short this code ?
I know this is little complicated hence please ask if any more information required.
Thanks in advance !!
You can have a helper subfunction:
Private Sub SetButton(ByVal ButtonId As Long, ByVal Enabled As Boolean)
Dim BackColor As Long
If Enabled Then
BackColor = RGB(100, 250, 100)
Else
BackColor = RGB(250, 100, 100)
End If
With Me("btn" & Cstr(Id))
.Enabled = Enabled
.Gradient = 12
.BackColor = BackColor
End With
End Sub
Then call this in the OnClick event like:
For Id = 1 To 8
Select Case Id
Case 1, 2, 4, 7
SetButton Id, True
Case Else
SetButton Id, False
End Select
Next

Can I store the same option value for more than one toggle button in a control box?

I have a list of questions each with 4 possible answers that are displayed as toggle buttons on my form. What I want to do is if the user chooses either of the first two buttons, the Option Value stored is "1", if they choose either of the last two buttons, the Option Value stored should be "0". The option values must be different for each toggle button in a control group. Is there a way to recode the toggle buttons to store the desired response? (I work in psychology, thus the bait and switch of offering 4 choices to the user when really only two responses are recorded).
Here is what I have tried:
I tried thinking about a recode as jcarroll suggested, but this is a circular reference:
Private Sub Q1_Click()
If Me.Q1 = 1 Or 2 Then
Me.Q1 = 1
Else:
Me.Q1 = 0
End If
End Sub
I could recode into another variable but that is just as clunky as using a SQL statement on the data post-hoc, for instance:
NewVariable=Iif([Q1]=1,1,iif([Q1]=2,1,0)
Finally, I tried to code have both toggle buttons have the same Option Value (which causes both to look pressed if either is pressed) and recode the unpressed toggle button's back color. But while my code looks correct to me, this did not change the pressed color of the toggle button (which I think has to do with over riding toggle button design settings):
Private Sub Frame5_Click()
If Toggle8.Value = True Then
Toggle9.BackColor = &HFF00&
Else
Toggle9.BackColor = &H8000000F
End If
End Sub
I could not come up with any programming solutions on the form itself to solve this. The alternative is that I wrote a procedure to apply to the data after it is collected which will be stored as 1,2,3,4 to convert it to 0 or 1. This procedure also sums up the 1's. I have 50 variables/questions that will be passed through this procedure (as well as another like it that converts 3&4 to 1).
Public Function Recode1(ParamArray arg()) As Variant
Dim Size As Integer, skips As Integer, i As Integer, result As Variant
'Recodes first two toggle buttons as "1" for AQ assessment
Size = UBound(arg) + 1
For i = 0 To Size - 1
If IsNull(arg(i)) Or Not (IsNumeric(arg(i))) Or arg(i) = -99 Then
skips = skips + 1
Else
If arg(i) = 1 Or arg(i) = 2 Then
result = result + 1
Else:
result = result + 0
End If
End If
End sub

Why won't the ForeColor of this label visibly change when altered in a loop?

I am making a form that has groups of controls that I want to visibly enable/disable with a related toggle button (let's call them Group Toggles). Each group has a different variety of control types, so I made a common procedure to handle the toggling:
'constants for control ForeColors
Public Enum LabelForeColor
Default = 8355711
Off = 14277081
End Enum
Public Enum ListForeColor
Default = 4210752
Off = 12566463
End Enum
Public Sub EnableControl(Ctrl As Control, Enabled As Boolean)
With Ctrl
Select Case Ctrl.ControlType
Case acLabel
If Enabled Then .ForeColor = LabelForeColor.Default Else .ForeColor = LabelForeColor.Off
Debug.Print "LABEL", .ForeColor
Case acListBox
If Enabled Then .ForeColor = ListForeColor.Default Else .ForeColor = ListForeColor.Off
.Enabled = Enabled
Debug.Print "LIST", .ForeColor
Case acCommandButton
.Enabled = Enabled
Debug.Print "BUTTON", "NA"
Case acCheckBox
.Enabled = Enabled
Debug.Print "CHECK", "NA"
Case Else
Debug.Print "Control [" & .Name & "] is not of a type that EnableControl can handle."
End Select
End With
End Sub
Each group of controls is represented by a collection. When the form is loaded, every control with a particular tag property is added to the corresponding collection. The Group Toggles are not added to any collection and instead have event procedures that look like this:
Private Sub ToggleGroup1_AfterUpdate()
Dim State As Boolean
'a public function that converts the toggle button's value to a boolean
State = FormCommon.ToggleButtonState(ToggleGroup1.Value)
Dim iCtrl As Control
For Each iCtrl In Controls_ByPlant
FormCommon.EnableControl iCtrl, State
Next iCtrl
End Sub
When I click on a GroupToggle, all of the controls in the corresponding group visibly change appropriately, except for the labels. After an hour of troubleshooting, here's what I know:
The ForeColor property of the label does change, but not visibly.
When I call EnableControl on a label outside of a loop, the label visibly changes.
It doesn't matter if I pass the label object specifically to the subroutine or if I pass it from its group collection; the change is visible in both cases
If I toggle-disabled a label as part of the Group Toggle event and then call EnableControl specifically on that label to try to disable it again, there is no visible change (probably because the ForeColor property is already set to the "off" color)
Turning screen updating off with Application.Echo while the Group Toggle event runs and then turning it back on at the end of the event does not make a difference.
Making the Group Toggle event run with a For i = 1 to .Count instead of a For Each does not make a difference.
This problem also occurs when changing a different visual property instead, such as ForeTint.
(Per comments) Repaint does not make a difference
(Per comments) DoEvents does not make a difference
Why is this happening?
(First ever question, so apologies if I messed something up in the post)
This was interesting, but somewhat anticlimactic.
Your code does work for the labels, but what happens is this:
All labels are associated with input controls (as it is usual)
When you deactivate a group, you disable the input controls (.Enabled = Enabled)
This automatically sets the associated labels to a (system defined) light gray text color which cannot be changed.
This "disabled label" color is very similar to your LabelForeColor.Default color, so it is hard to see the change when toggling. But it does change.
Change your color constants to make the effect more visible:
Public Enum LabelForeColor
Default = vbRed ' 8355711
' the "Off" color is never visible, unless you add an un-associated label to a group
Off = vbBlue ' 14277081
End Enum
Edit: your test code FormCommon.EnableControl iCtrl, False works, because it only affects the label, but doesn't disable its associated list box.

VBA code that changes background color of form conditionally by answer

I want to use VBA (or some other solution) to conditionally change the background color of a form based off what number users enter in a numeric field. Basically, after they enter their answer to the Starter question, if they entered 1 then I want the form background to change to a specific shade of blue, and if they entered 2 then I want the form background to change to a specific shade of green. I saw a code that looks like it would be very similar to my need in another question on here, but I couldn't figure out how to make the code work, and was having trouble figuring out exactly how/where to put each module.
Some information:
The field I want it to be based off of is numeric, called Starter, and through data validation users are limited to entering 1, 2, 9, or leaving it blank. I only want the color to change if it's entered as 1 or 2.
I'm using Access 2010
the form has neither header nor footer
the code I was attempting to use and made some alterations to is the following:
Private Sub Form_AfterUpdate()
blue_yes = "15325906"
green_no = "13888226"
Dim colorThis As String
booWhatever = Me.Starter ''Use of the variable can prevent problems
If booWhatever = 1 Then
colorThis = "blue_yes"
End If
If booWhatever = 2 Then
colorThis = "green_no"
End If
subFrm.Form.Section(acDetail).BackColor = colorThis
subFrm.Form.Repaint
End Sub
I've also managed, off a very different piece of code, to sort of do what I want, but the way it's working it seems to change the status of all forms, not just the one I'm currently working with, which is the goal. So for example if I enter 2 to starter, it changes the background color of every single record's form.
Private Sub Starter_AfterUpdate()
If Me.Starter = "1" Then Me.Detail.BackColor = vbBlue
If Me.Starter = "2" Then Me.Detail.BackColor = vbGreen
End Sub
EDIT:
Welp, embarrassingly I found the solution. It's not a very neat one, but it works.
Private Sub Form_Current()
Dim Presence As String
Presence = Nz(Me.Starter.Value, 9)
Select Case Presence
Case "1"
Me.Detail.BackColor = 15325906
Case "2"
Me.Detail.BackColor = 13888226
Case Else
Me.Detail.BackColor = vbWhite
End Select
End Sub
Private Sub Starter_AfterUpdate()
Dim Presence As String
Presence = Nz(Me.Starter.Value, 9)
Select Case Presence
Case "1"
Me.Detail.BackColor = 15325906
Case "2"
Me.Detail.BackColor = 13888226
Case Else
Me.Detail.BackColor = vbWhite
End Select
End Sub
I know it is a really old question (probably you have already solved it in a better way) but I will give it a try anyways.
Try the following:
Private Sub Text0_Change()
Select Case Me.Text0.Text
Case ""
Case "1"
Me.Detail.BackColor = 15325906
Case "2"
Me.Detail.BackColor = 13888226
Case Else
Me.Detail.BackColor = vbWhite
End Select
End Sub
EDIT:
I tried that and it works I think now as it supposed to do.
When you change the text on the text box triggers this event every time, runs the Sub, checks it's own text and changes the color of the form as described.
The change is that I changed the property of the field it checks. From Value to Text. We want when the event triggers to check the current text because the Value property updates when you "finish" with the textbox (after you press enter or the focus on the control is lost) and we want the change to happen the same moment we press the key changing the value and not later.
The second change and the reason we got strange patterns before is that I have added one more Case when the text is "" to do nothing on that change (empty case). Without that case when we used delete or backspace to remove the text and left the textbox empty ("") then the case else was True and it changed the background color.
I hope this is the correct answer now. Please let me know!

Reporting Services Conditional Row Color

I have a report that shows client names jsut in a list like so:
ATK
FLD
FLD
DB
DB
DB
BL
I already have them grouped and everything but I am wondering if there is a way to make it so I can have each client seperated by color, for example white then grey then white then grey etc.
Right now I am using background color as the following:
=IIF(RowNumber(Nothing) Mod 2,"Gainsboro","White")
This just makes every other row white or grey. Is there a way to make every other client white or grey?
In the custom code for the report add the following:-
Public shared currentRowColour as string = "Red"
public function GetBackGroundColour(previousValue as string, currentValue as string) as string
if previousValue <> currentValue then
if currentRowColour = "Red" then
currentRowColour ="Orange"
else
currentRowColour ="Red"
end if
end if
return currentRowColour
end function
Then edit the expression for the background colour for your text box (or row)
=Code.GetBackGroundColour(Previous(Fields!.Value), Fields!.Value)