Another quick question for ya...
Here's my button code, and I want to see if I can do something different so I don't have to repeat the same code for each of my 14 buttons in my option group: -
Private Sub grpS1_LostFocus()
-
-
Dim intCount As Integer
-
Dim lngRed As Long, lngBlack As Long
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
intCount = DCount("[RspnsID]", "qxtbChkSectionsComplete")
-
-
If intCount > 0 Then
-
' missing questions, change button ForeColor to red
-
Me!grpS1.ForeColor = lngRed
-
Me!grpS1.PressedForeColor = lngRed
-
Me!grpS1.HoverForeColor = lngRed
-
Else
-
' questions complete, change button ForeColor to black
-
Me!grpS1.ForeColor = lngBlack
-
Me!grpS1.PressedForeColor = lngBlack
-
Me!grpS1.HoverForeColor = lngBlack
-
End If
-
-
End Sub
-
The buttons in the option group "grpSections" are named grpS1 - grpS14 and represent sections on my questionnaire. The query above uses the value of the option group as criteria with [Forms]![frmMain].[Controls]![grpSections].[value] to calculate the DCount on RspnsID for each section.
So it all boils down to this. Is there a way to put code in the option group's on click or after update event to grab the value of the button that has just lost focus, to run the query above and change THAT button fore color? So for example as a user goes from section 1 to 2 by clicking the grpS2 button the query would check for complete questions in section 1 and if there are questions missed then change the fore color for grpS1.
As always, thanks everyone for your help!
11 5256 - To change the ForeColor of all ToggleButtons within the grpSections Option Group:
- Dim ctl As Control
-
-
For Each ctl In Me.Controls
-
If ctl.ControlType = acToggleButton And Left$(ctl.Name, 4) = "grpS" Then
-
ctl.ForeColor = vbBlack
-
End If
-
Next
- I couldn't figure out an easy way to accomplish your second question, but that doesn't mean that one does not exist. I devised what I feel is a simple Method of retaining a Reference to the Last Toggle Button pressed, and here it goes:
- Declare a Form Level variable to hold a Reference to the Last Toggle Button pressed:
- Private ctlLast As ToggleButton
- In the LostFocus() Event of each Toggle Button in the Option Group (2nd Button used for Demo), place the following line of Code to explicitly refer to that Button:
- Private Sub grpS2_LostFocus()
-
Set ctlLast = Me!grpS2
-
End Sub
- To now Change the ForeColor Property of the Last Toggle Button pressed in the Option Group:
- ctlLast.ForeColor = vbRed
- As I stated earlier, an easier approach may exist, so keep monitoring this Thread.
- Any questions, feel free to ask.
Oops. spoke too soon. Seems to change all to red not taking into account if there are missed questions. Testing, be back in a bit with more.
Working now. Set this as a public variable: -
Public Sub changeColor(ctrl As Access.Control)
-
Dim intCount As Integer
-
Dim lngRed As Long, lngBlack As Long
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
intCount = DCount("[RspnsID]", "qxtbChkSectionsComplete")
-
-
If intCount > 0 Then
-
' missing questions, change button ForeColor to lngRed
-
With ctrl
-
.ForeColor = lngRed
-
.PressedForeColor = lngRed
-
.HoverForeColor = lngRed
-
End With
-
Else
-
' questions complete, change button ForeColor to lngBlack
-
With ctrl
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
-
End Sub
-
Then, in the option groups after update event, this: -
-
Select Case Me.grpSections.Value
-
Case 1
-
Call changeColor(Me.grpS1)
-
Case 2
-
Call changeColor(Me.grpS2)
-
Case 3
-
Call changeColor(Me.grpS3)
-
.
-
.
-
.
-
to case 15
-
End Select
-
Then in the forms open event, this, to change the default color to black (also put this in a few buttons on the form when changing records): -
Dim intCount As Integer
-
Dim ctl As Access.Control
-
Dim lngRed As Long, lngBlack As Long
-
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
intCount = DSum("intSections", "qDSections2")
-
For Each ctl In Me.Controls
-
If TypeOf ctl Is ToggleButton Then
-
If ctl.Tag > intCount Then
-
ctl.Visible = False
-
Else
-
ctl.Visible = True
-
With ctl
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
-
End If
-
Next ctl
-
So on to the next challenge!
ok. Code is updating the fore color but it seems to change from black to red with sections that have unanswered questions and when all the questions are answered you have to click back through each section to get the color to switch from red (missed questions) to black. So maybe a combo approach will do the trick.
Private variable at form level set as such: - Private ctlLast As ToggleButton
... code for the option group after update event: -
Private Sub grpSections_AfterUpdate()
-
Call changeColor(ctlLast)
-
End Sub
-
... button lost focus events (on each button) -
Private Sub grpS1_LostFocus()
-
Set ctlLast = Me!grpS1
-
End Sub
-
... and the function -
Public Function changeColor(ctlLast)
-
'Dim ctlLast As ToggleButton
-
Dim intCount As Integer
-
Dim lngRed As Long, lngBlack As Long
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
Debug.Print ctlLast '<<<<< error here, "entered expression that has no value"
-
-
intCount = DCount("[RspnsID]", "qxtbChkSectionsComplete")
-
-
If intCount > 0 Then
-
' missing questions, change button ForeColor to lngRed
-
With ctlLast
-
.ForeColor = lngRed
-
.PressedForeColor = lngRed
-
.HoverForeColor = lngRed
-
End With
-
Else
-
' questions complete, change button ForeColor to lngBlack
-
With ctlLast
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
-
End Function
-
Seems variable has no value?
Works fine from this end, are you sure that you are setting the Value of ctlLast in the 'LostFocus()' Event and for each Toggle Button grpS1 thru grpS14?
yep. btw, I only have some of the toggles visible when the form loads, depending on how many sections I have in the current survey. I don't think this would be causing the issue. This code for the forms on open event is -
Dim intCount As Integer
-
Dim ctl As Access.Control
-
Dim lngRed As Long, lngBlack As Long
-
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
intCount = DSum("intSections", "qDSections2")
-
For Each ctl In Me.Controls
-
If TypeOf ctl Is ToggleButton And Left$(ctl.Name, 4) = "grpS" Then
-
If ctl.Tag > intCount Then
-
ctl.Visible = False
-
Else
-
ctl.Visible = True
-
With ctl
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
-
End If
-
Next ctl
-
- Is the code in the Form's Open() Event working as it should?
- intSections in the DSum() Function appears to be a Variable Name, is it an actual Field contained in qDSections2?
- intCount = DSum("intSections", "qDSections2")
Yes it is working. I've tried shutting down the db with red colored buttons and it opens with black. Also, I've added/subtracted sections on my survey and the representative sections buttons come and go as expected.
So the last code I posted is working on your end? Very strange. I am running A2010 (but tested it on 07 as well with same results).
Here's the two queries mentioned:
qDSections1 -
SELECT tblQuestions.SectionID, Count(tblQuestions.SectionID) AS CountOfSectionID
-
FROM tblQuestions
-
WHERE (((tblQuestions.QstnIsActive)=True))
-
GROUP BY tblQuestions.SectionID;
-
qDSections2 -
SELECT Count(*) AS intSections
-
FROM qDSections1;
-
Maybe it is where I placed the variable reference. This code - Private ctlLast As ToggleButton
I placed in the declaration section of Form_frmMain (just above Option Explicit). Should it not be Public instead?
I CAN pass the tag value of the button as a string variable so maybe I can work from that angle. Not sure so any help is appreciated.
All is well now. I ditched the function and instead placed this code in the groups after update event -
Dim intCount As Integer
-
Dim lngRed As Long, lngBlack As Long
-
lngRed = RGB(186, 20, 25)
-
lngBlack = RGB(64, 64, 64)
-
-
intCount = DCount("[RspnsID]", "qxtbChkSectionsComplete")
-
-
If intCount > 0 Then
-
' missing questions, change button ForeColor to lngRed
-
With ctlLast
-
.ForeColor = lngRed
-
.PressedForeColor = lngRed
-
.HoverForeColor = lngRed
-
End With
-
Else
-
' questions complete, change button ForeColor to lngBlack
-
With ctlLast
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
-
-
The buttons themselves have this as their lost focus event as you provided -
Private Sub grpS1_LostFocus()
-
Set ctlLast = Me.grpS1
-
End Sub
-
and this as the variable declaration - Private ctlLast As ToggleButton
Thanks for the help once again ADezii.
arghh!
So now I need to get the VALUE of ctlLast to pass it as a criteria in my query. - intCount = DCount("[RspnsID]", "qxtbChkSectionsComplete")
-
-
If intCount > 0 Then
-
' missing questions, change button ForeColor to lngRed
-
With ctlLast
-
.ForeColor = lngRed
-
.PressedForeColor = lngRed
-
.HoverForeColor = lngRed
-
End With
-
Else
-
' questions complete, change button ForeColor to lngBlack
-
With ctlLast
-
.ForeColor = lngBlack
-
.PressedForeColor = lngBlack
-
.HoverForeColor = lngBlack
-
End With
-
End If
Right now, the query gets it's criteria value from - [Forms]![frmMain].[Controls]![grpSections].[value]
so it is the current value of the control, not the last value.
Seems I'm chasing my tail ;)
Still chasing, but getting somewhere I think. After some study I settled on the following which works but seems clunky. Let me know what you think.
In the lost focus of each option button I put this: -
Private Sub grpS1_LostFocus()
-
Set ctlLast = Me.grpS1 'grabs the name of the button
-
intLastValue = Me.grpSections.Value 'grabs the value of the button
-
setLastValue intLastValue
-
End Sub
-
Then added this: -
Option Compare Database
-
Private intLastValue As Integer
-
Public Sub setLastValue(Value As Integer)
-
intLastValue = Value
-
End Sub
-
And this: -
Public Function GetLastValue()
-
GetLastValue = intLastValue
-
End Function
-
Then put this in as a criteria in my query:
The after update event for the option group remained unchanged and is shown above.
This is WAY over my head but I'm beginning to see the light. Seems like I've got an extra step in here somewhere.
Nite all.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: What-a-Tool |
last post by:
I have a school project (ASP) in which I have to call three different ASP
pages from three different and identical (except for the form "action",
obviously) HTM pages. This I have no problem with....
|
by: Corrine |
last post by:
Is there a way to cancel a change in an option group? The option group still
changes to the option clicked on when clicking on the NO button with the
following code in the BeforeUpdate event of the...
|
by: kufre |
last post by:
I need some help. I have a option group button that contain two
checkbox call Active and Inactive on my Filing form. This is what I
want, the Active box will alway be the default checkbox,the...
|
by: MLH |
last post by:
Why is that?
If I choose the tiny check boxes which are hard to
hit with a mouse, it works fine. But option buttions,
shich can be sized big enough for people with limited
sight and dexterity...
|
by: AA Arens |
last post by:
I use a sewt of buttons, created from the "Option Group". I would like
to have the pushed button appearing in another color, so it is more
clearier which button is pushed. How to proceed it? I am...
|
by: hackerslacker |
last post by:
I have an ordering form that use two combo boxes to filter down the
records of a Products table. This worked fine with the after_Update of
the first filtering the records and creating the...
|
by: sparks |
last post by:
When you enter an option group you can move to each option with the
arrow keys and select with the space bar.
Option groups don't have keydown events so has
anyone come up with a way to allow...
|
by: Student1000 |
last post by:
Help me out please...
Ok, i have been trying to do this for months….I kinda gave up on it but am back at it again.
I created a form for a table (Bills). In the form, I have three option buttons...
|
by: sparks |
last post by:
well I am trying to get around looking at all the buttons with a case
statement so I was trying this.
Public Sub looking(ctlname)
Dim ctl As OptionGroup
Dim btn As ToggleButton
ctl =...
|
by: sara |
last post by:
Hi
I'm having a very strange problem and need HELP!!
I have a form for the user to choose a report (radio button in an
option group) and parameters (Dates, Season).
Click the option button,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |