Conditional Enabling of Options Group Toggle Button

T

Ted

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.

-ted
 
M

Marshall Barton

Ted said:
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.


Use code in both the study date text box's AfterUpdate and
in the Form's Current event:

If Me.OffStudyDate <complete condition> Then
Me.option6.Enabled = True
Else
Me.option6.Enabled = False
End If
 
T

Ted

hi marsh,

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
 
M

Marshall Barton

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
 
T

Ted

hi marsh,

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?

any suggestions..

-ted


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




Marshall Barton said:
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
--
Marsh
MVP [MS Access]

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!
 
M

Marshall Barton

You should be able to avoid the AfterUpdate event by adding:
Cancel = True
to the BeforeUpdate event (right after the Undo)
 
T

Ted

hi,

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]

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
 
M

Marshall Barton

Sorry, Ted, but that's too much to ask in a newsgroup,
especially when I don't have a full picture of what it is
supposed to do in all these various situations.

I think you should go through the usual debugging procedures
of placing break points and judiciously placing some
Debug.Print statements to check the circumstances and values
of all the pertinate controls and variables.

I did scan through the code for obvious mistakes and spotted
one issue that definitely needs to be dealt with. The
OffStudyDate_AfterUpdate procedure contains the statement
Cancel = True
which has no meaning in an AfterUpdate event. This raises
the question of how you can successfully compile the module?
The only way I can think of is that you do not have the
statement
OPTION EXPLICIT
at the top of the module. The use of OPTION EXPLICIT
prevents you from using undefined variables/arguments and
helps catch issues at compile time instead of during runtime
testing.

NOTE: When working on VBA code, you should always switch
the form to design view before editing its code module.
After making changes to the module, you should use the Debug
- Compile menu item to explicitly compile the code and catch
any compile time errors. This way the compiler can provide
more meaningful error messages than you can get if all that
is happening during run time testing. Do not switch the
form back to form view until you can compile the module
without error.
--
Marsh
MVP [MS Access]

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]

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.


:
Use code in both the study date text box's AfterUpdate and
in the Form's Current event:

If Me.OffStudyDate <complete condition> Then
Me.option6.Enabled = True
Else
Me.option6.Enabled = False
End If
 
T

Ted

thanks marsh, that's how i thought i had it set up (OPTION EXPLICT) but
you're right -- it should be there; inserting the OE statement & compiling
picked up the Cancel=True point in your mention.

i was a bit reluctant to post all the pertinent gory details but desperation
got the better of my good sense. glad you took it all in stride and thanks
for the bandwidth.

with regards,

-ted

Marshall Barton said:
Sorry, Ted, but that's too much to ask in a newsgroup,
especially when I don't have a full picture of what it is
supposed to do in all these various situations.

I think you should go through the usual debugging procedures
of placing break points and judiciously placing some
Debug.Print statements to check the circumstances and values
of all the pertinate controls and variables.

I did scan through the code for obvious mistakes and spotted
one issue that definitely needs to be dealt with. The
OffStudyDate_AfterUpdate procedure contains the statement
Cancel = True
which has no meaning in an AfterUpdate event. This raises
the question of how you can successfully compile the module?
The only way I can think of is that you do not have the
statement
OPTION EXPLICIT
at the top of the module. The use of OPTION EXPLICIT
prevents you from using undefined variables/arguments and
helps catch issues at compile time instead of during runtime
testing.

NOTE: When working on VBA code, you should always switch
the form to design view before editing its code module.
After making changes to the module, you should use the Debug
- Compile menu item to explicitly compile the code and catch
any compile time errors. This way the compiler can provide
more meaningful error messages than you can get if all that
is happening during run time testing. Do not switch the
form back to form view until you can compile the module
without error.
--
Marsh
MVP [MS Access]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top