would you mind looking at the expanded version of my vba that i'm writing to
deal with this case? it doesn't get me what i am wanting.
Private Sub Frame1_AfterUpdate()
Dim Response As Long
Dim Results As Integer
Select Case Frame1.Value
Case 1
Me.Onlistdate.SetFocus
If myvarOldValue = 5 Or myvarOldValue = 6 _
Or myvarOldValue = 7 Then
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
End If
Case 2
Me.REgisteredDAte.SetFocus
If myvarOldValue = 5 Or myvarOldValue = 6 _
Or myvarOldValue = 7 Then
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
End If
Case 3
Me.OnStudyDate.SetFocus
If myvarOldValue = 5 Or myvarOldValue = 6 _
Or myvarOldValue = 7 Then
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
End If
Case 4
Me.TXEndedDate.SetFocus
If myvarOldValue = 5 Or myvarOldValue = 6 Or myvarOldValue =
7 Then
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
End If
Case 5
Me.OffStudyDate.SetFocus
If myvarOldValue = 1 Or myvarOldValue = 2 Or myvarOldValue =
3 Or myvarOldValue = 4 _
And IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = False
Results = MsgBox("You have failed to enter a valid Off
Study Date", vbOKOnly + vbCritical, "Alert!")
ElseIf myvarOldValue = 1 Or myvarOldValue = 2 Or
myvarOldValue = 3 Or myvarOldValue = 4 _
And Not IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = True
DoCmd.RunMacro ("Append Off Study Pxs--Edit Form")
ElseIf myvarOldValue = 6 Or myvarOldValue = 7 And
IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = False
Results = MsgBox("You have failed to enter a valid Off
Study Date", vbOKOnly + vbCritical, "Alert!")
ElseIf myvarOldValue = 6 Or myvarOldValue = 7 And Not
IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = True
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
DoCmd.RunMacro ("Append Off Study Pxs--Edit Form")
End If
Case 6
Me.LTFUDate.SetFocus
If myvarOldValue = 5 Then
DoCmd.RunMacro ("Update DEAD Off Study Pxs--Edit Form")
Else: Results = MsgBox("You have coded this Patient as
either Dead or LTFU. First code this Patient as being Off Study!!!", vbOKOnly
+ vbCritical, "Alert!")
End If
Case 7
Me.DateDth.SetFocus
If myvarOldValue = 5 Then
DoCmd.RunMacro ("Update LFU Off Study Pxs--Edit Form")
Else: Results = MsgBox("You have coded this Patient as
either Dead or LTFU. First code this Patient as being Off Study!!!", vbOKOnly
+ vbCritical, "Alert!")
End If
Case Else
End Select
myvarOldValue = Me.Frame1 ' myvarOldValue is a Module Level vble which
handles the earlier value of the options group
End Sub
the AFterupdate of the options group Frame1 above is followed by the
BeforeUpdae of Frame1
Private Sub Frame1_BeforeUpdate(Cancel As Integer)
Dim lngRetVal As Long
ToggleColor
If Me.Dirty = True And myvarOldValue <> 5 And Me.Frame1 = 5 And _
IsNull(Me.SequenceNum) Then
lngRetVal = MsgBox("You are attempting to code this Px as OFF STUDY.
Sequence Number is Required! ALL CHANGES TO THIS PATIENT'S RECORD WILL BE
LOST!!", vbOKOnly + vbCritical, "Critical")
Me.Frame1.Undo
Cancel = True <-- per recent email
End If
End Sub
there is an AfterUpdate event attached to OffStudyDate
Private Sub OffStudyDate_AfterUpdate()
If IsNull(Me.OffStudyDate) = True And Me.Frame1 = 5 Then ' also in OnCurrent
Me.Toggle11.Enabled = False
Else
Me.Frame1.Value = Me.Frame1.OldValue
Me.Toggle11.Enabled = True
Cancel = True
End If
End Sub
in the OnCurrentEvent for the form we have
Private Sub Form_Current()
ToggleColor
If Me.FilterDates.ForeColor = lngRed Then
Me.FilterLbl.Visible = True
Else
Me.FilterLbl.Visible = False
End If
myvarOldValue = Me.Frame1 ' see also Frame1 AfterUpdate event handling
If IsNull(Me.OffStudyDate) = True And Me.Frame1 = 5 Then ' also in
OffStudyDate AfterUPdate
Me.Toggle11.Enabled = False
Else: Me.Toggle11.Enabled = True
End If
End Sub
best,
-ted
Marshall Barton said:
You should be able to avoid the AfterUpdate event by adding:
Cancel = True
to the BeforeUpdate event (right after the Undo)
--
Marsh
MVP [MS Access]
Ted wrote:
i don't know if it's important to continue this thread or start a new one.....
in the same a2k mdb, in the same Frame1, i have a BeforeUpdate event which
is actuated when user selects Case 5.
Private Sub Frame1_BeforeUpdate(Cancel As Integer)
Dim lngRetVal As Long
ToggleColor
If Me.Dirty = True And myvarOldValue <> 5 And Me.Frame1 = 5 And _
IsNull(Me.SequenceNum) Then
lngRetVal = MsgBox("You are attempting to code this Px as 'Off Study'.
Sequence Number is Required! The value will be restored.", vbOKOnly +
vbCritical, "Critical")
Me.Frame1.Undo
End If
End Sub
since i don't want the AfterUpdate action to happen (vba below) as written,
i think i should be trying to undo the action of the users selecting the case
5 (Toggle11) option button. vba (as written above) doesn't have the desired
outcome?
Case 5
Me.OffStudyDate.SetFocus
If myvarOldValue = 1 Or myvarOldValue = 2 Or myvarOldValue =
3 Or myvarOldValue = 4 _
And IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = False
Results = MsgBox("You have failed to enter a valid Off
Study Date", vbOKOnly + vbCritical, "Alert!")
ElseIf myvarOldValue = 1 Or myvarOldValue = 2 Or
myvarOldValue = 3 Or myvarOldValue = 4 _
And Not IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = True
DoCmd.RunMacro ("Append Off Study Pxs--Edit Form")
ElseIf myvarOldValue = 6 Or myvarOldValue = 7 And
IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = False
Results = MsgBox("You have failed to enter a valid Off
Study Date", vbOKOnly + vbCritical, "Alert!")
ElseIf myvarOldValue = 6 Or myvarOldValue = 7 And Not
IsNull(OffStudyDate) Then
Me.Toggle11.Enabled = True
DoCmd.RunMacro ("Delete Off Study Pxs--Edit Form")
DoCmd.RunMacro ("Append Off Study Pxs--Edit Form")
End If
:
If you do need further assistance with the enable thing,
please explain what needs to be checked before you want the
option button enabled.
For your new question, use the option group's BeforeUpdate
event:
If <some other condition> Then
MsgBox "whoops, you forgot the other condition"
Cancel = True
End If
Ted wrote:
that looks like it should work (and i'll get back to let y'know if it proves
otherwise)
perhaps this is on a different thread/topic, but suppose the user presses an
option button and some other condition which should have been true isn't and
you alert the user with a msgbox saying such and such.....could you set
things up so that when the user clicks 'Ok' or whatever on the msgbox the
depressed option group button is 'restore' (and the previously selected
button is depressed)? l
whatever the case, thanks for the tip on this!
Ted wrote:
i use A2K.
i have an Options Group named Frame1 with seven possible values. the Case 6
button is associated with an OffStudyDate control alongside in the sense that
when the button gets selected it launches a macro linked to an append query
which (among other variables) apends OffStudyDate to the target table. so
it's imperative that OffStudyDate be complete before selecting Case 6.
i'm wondering if there's some way to 'disable' the Case 6 button until the
condition i just described is met. a message box telling the user to enter
the OffStudyDate would also be not a bad idea as well i reckon.
any thoughts, suggestions? to get things going, in case there are, the
options group is called Frame1, the Case 6 button's called Toggle11.