tfurnivall
New Member
- Joined
- Jan 15, 2012
- Messages
- 48
BACKGROUND
I have an application which allows a user to create various reports. The underlying data for the application is always available for update. When the data has changed, the data is no long 'valid' for reporting until a particular procedure (the Analyze) procedure has been run. I have a configuration item (ReportDataIsValid) that I can set to true or false from anywhere in the application. This allows the state of the data to be preserved across different invocations of the application. When the application is opened, the state of this item is checked, and the application interface is configured appropriately:
Similarly, every time the Analyze procedure is run it sets the configuration item and the checkbox to true, and every time an Update procedure is run. it sets the configuration item, and the checkbox to false. So far, so good. It works!
CONFESSION
Being the sort of developer who likes to allow myself the luxury of a short cut, I want to be able to IN-validate (or RE-validate) the data without running either an Update or the Analyze procedure.
This led to the following code for the checkbox in the Configuration form:
So, any time the button is clicked, regardless of the state of the little check-mark on the screen, the following things happen:
1) The configuration item is set to false, so the next time the application starts up it will maintain this 'not-valid' state
2) The Report tab on the main form selector is set to invisible. I.e. the reports can not be accessed.
3) The little checkmark is cleared.
All of this is done with event handling turned off, so that we do not get into a race condition. It works.
THE REAL PROBLEM
Now for the heart of the problem. I want to be able to RE-validate the data condition. After all, it really hasn't changed, I'm simply developing and testing different aspects of the application. So, to RE-validate, I want to use Ctrl/Alt and then a click on the checkbox control (chkReportDataIsValid). No provision for testing the state of the Ctrl and Alt keys in a regular click, so I switch to MouseDown for the same event. This is a little more complex:
This is exactly the same code if we do not have the 'magic' shft value, and exactly the reverse if we do. For Ctrl/Shift-Click the folloing happens:
1) The configuration item is set to True
2) The Reports tab is made visible (and thus accessible)
3) The little check mark is turned on in the control.
Again, all of this is with event handling disabled. (I've also commented out the code in the original handler, so there is no contention there!
However, IT DOESN'T WORK!
Here is what I get in the Immediate window when I try it - using two clicks on each state of the control (twowith no magic shift, two WITH a magic shift):
I'm missing something somewhere, but I can't figure it out. Any takers?
Tony
I have an application which allows a user to create various reports. The underlying data for the application is always available for update. When the data has changed, the data is no long 'valid' for reporting until a particular procedure (the Analyze) procedure has been run. I have a configuration item (ReportDataIsValid) that I can set to true or false from anywhere in the application. This allows the state of the data to be preserved across different invocations of the application. When the application is opened, the state of this item is checked, and the application interface is configured appropriately:
Code:
if ReportDataIsValid then
' Make Report tabs visible, and set the configuration check box to 'true'
else
' Make the report tabs invisible and set the configuration check box to 'false'
endif
Similarly, every time the Analyze procedure is run it sets the configuration item and the checkbox to true, and every time an Update procedure is run. it sets the configuration item, and the checkbox to false. So far, so good. It works!
CONFESSION
Being the sort of developer who likes to allow myself the luxury of a short cut, I want to be able to IN-validate (or RE-validate) the data without running either an Update or the Analyze procedure.
This led to the following code for the checkbox in the Configuration form:
Code:
Private Sub chkValidReportData_Click()
' We can click to IN-validate the report data, but we can ONLY
' validate the report data by running the Analyze procedures.
' If we click the control 'into' a true state, then immediately set it to false.
If Not ProcessEvents Then
Exit Sub
End If
ProcessEvents = False
' Now set the things we want without fear of events being handled
ThisWorkbook.SetValidReportData (False)
mpDashboard.Pages("pgReports").Visible = False
Me.chkValidReportData = False
' Resume event handling
ProcessEvents = True
End Sub
So, any time the button is clicked, regardless of the state of the little check-mark on the screen, the following things happen:
1) The configuration item is set to false, so the next time the application starts up it will maintain this 'not-valid' state
2) The Report tab on the main form selector is set to invisible. I.e. the reports can not be accessed.
3) The little checkmark is cleared.
All of this is done with event handling turned off, so that we do not get into a race condition. It works.
THE REAL PROBLEM
Now for the heart of the problem. I want to be able to RE-validate the data condition. After all, it really hasn't changed, I'm simply developing and testing different aspects of the application. So, to RE-validate, I want to use Ctrl/Alt and then a click on the checkbox control (chkReportDataIsValid). No provision for testing the state of the Ctrl and Alt keys in a regular click, so I switch to MouseDown for the same event. This is a little more complex:
Code:
Private Sub chkValidReportData_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
' Allows us to see if we are doing a special "RE-validate Reports" (for testing purposes
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Worksheets("Configuration")
Debug.Print "Valid Reports: "; Me.chkValidReportData, "Shift="; Shift
If Not ProcessEvents Then
Exit Sub
End If
ProcessEvents = False
If Shift = 6 Then ' Ctrl + Alt
ThisWorkbook.SetValidReportData (True)
mpDashboard.Pages("pgReports").Visible = True
Me.chkValidReportData.Value = True
Debug.Print "Set Valid Reports: "; Me.chkValidReportData.Value
Else
ThisWorkbook.SetValidReportData (False)
mpDashboard.Pages("pgReports").Visible = False
Me.chkValidReportData.Value = False
Debug.Print "Set Valid Reports: "; Me.chkValidReportData.Value
End If
ProcessEvents = True
End Sub
This is exactly the same code if we do not have the 'magic' shft value, and exactly the reverse if we do. For Ctrl/Shift-Click the folloing happens:
1) The configuration item is set to True
2) The Reports tab is made visible (and thus accessible)
3) The little check mark is turned on in the control.
Again, all of this is with event handling disabled. (I've also commented out the code in the original handler, so there is no contention there!
However, IT DOESN'T WORK!
Here is what I get in the Immediate window when I try it - using two clicks on each state of the control (twowith no magic shift, two WITH a magic shift):
Code:
Valid Reports: True Shift= 0
Set Valid Reports: False
Valid Reports: True Shift= 0
Set Valid Reports: False
Valid Reports: True Shift= 6
Set Valid Reports: True
Valid Reports: False Shift= 6
Set Valid Reports: True
I'm missing something somewhere, but I can't figure it out. Any takers?
Tony