DrummerAndy
New Member
- Joined
- Aug 22, 2011
- Messages
- 14
I have a form to populate data/dates for testing.
There are two sections for testing: Test Plan Development (TPD) and System Testing (ST).
Each section can have one of four statuses: Upcoming, Active, On Hold, or Complete.
Each section also has a Begin Date and an End Date.
The fields on the form are organized in this order:
TPD Status, TPD Beg, TPD End
ST Status, ST Beg, ST End
There are rules in place (mostly on Exit events) that prevent certain combinations from happening. Here are some examples:
1. The end date cannot be before the begin date (for either section).
2. The ST begin date must be after the TPD begin date.
3. If the status is Upcoming, both dates must be in the future.
4. If the status is Active, begin can’t be in the future and end can’t be in the past (both can be today).
5. If the status is Complete, neither date can be in the future.
6. If TPD is Upcoming, then ST must also be Upcoming.
7. If TPD is On Hold then ST must be On Hold.
8. If TPD is Active, then ST can’t be Complete.
9. If ST is Active then TPD can’t be Upcoming.
There is nothing stopping people from clicking on whichever field they want and making a change regardless of order or what is populated on other fields. So it’s possible to create paradox situations when exiting a field. I want to allow the user to select what they need to correct using a Yes/No message box.
For example, if the TPD Status is Active, the TPD Begin Date must be in the future. So on exiting the begin date, I want to give the user the option of updating the status instead of changing the date. Here is my code:
When I click No it works fine but when I click Yes, the message pops up a second time then I get run-time error ‘-12147467259 (80004005). It appears that even though I'm already in the exit event for the field, since I try to set focus to the status, it goes back through the exit event a second time then errors out.
Can anyone help me with a solution? Thanks in advance for any help.
Andy
There are two sections for testing: Test Plan Development (TPD) and System Testing (ST).
Each section can have one of four statuses: Upcoming, Active, On Hold, or Complete.
Each section also has a Begin Date and an End Date.
The fields on the form are organized in this order:
TPD Status, TPD Beg, TPD End
ST Status, ST Beg, ST End
There are rules in place (mostly on Exit events) that prevent certain combinations from happening. Here are some examples:
1. The end date cannot be before the begin date (for either section).
2. The ST begin date must be after the TPD begin date.
3. If the status is Upcoming, both dates must be in the future.
4. If the status is Active, begin can’t be in the future and end can’t be in the past (both can be today).
5. If the status is Complete, neither date can be in the future.
6. If TPD is Upcoming, then ST must also be Upcoming.
7. If TPD is On Hold then ST must be On Hold.
8. If TPD is Active, then ST can’t be Complete.
9. If ST is Active then TPD can’t be Upcoming.
There is nothing stopping people from clicking on whichever field they want and making a change regardless of order or what is populated on other fields. So it’s possible to create paradox situations when exiting a field. I want to allow the user to select what they need to correct using a Yes/No message box.
For example, if the TPD Status is Active, the TPD Begin Date must be in the future. So on exiting the begin date, I want to give the user the option of updating the status instead of changing the date. Here is my code:
Code:
Private Sub txtTPDB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With txtTPDB
'If TPD Status is Active then Begin Date cannot be in the future
If Me.cbTPDS = "1-Active" And .Value > txtToday.Value Then
.BackColor = &HFF
MSG = MsgBox("Since the TPD Status is Active, the TPD Begin Date cannot be in the future! Do you want to change the TPD Status?", vbYesNo, "Status/Date Mismatch!")
If MSG = vbYes Then
Me.cbTPDS.SetFocus
Me.cbTPDS.SelStart = 0
Me.cbTPDS.SelLength = Len(.Text)
Cancel = True
Exit Sub
Else
.SelStart = 0
.SelLength = Len(.Text)
Cancel = True
Exit Sub
End If
End If
End With
End Sub
When I click No it works fine but when I click Yes, the message pops up a second time then I get run-time error ‘-12147467259 (80004005). It appears that even though I'm already in the exit event for the field, since I try to set focus to the status, it goes back through the exit event a second time then errors out.
Can anyone help me with a solution? Thanks in advance for any help.
Andy