Prompt before clearing data after unchecking checkbox?

P

Pat Dools

Hello,

I have the following code which will clear data from a number of 'Goals'
fields if a checkbox (that signals if they had 'Goals' in the first place)
that was checked is then un-checked. I have a message box informing the user
that this data will be wiped out. But, what I can't figure out is how to
warn the user first with a Yes/No vb message box, that if the user chooses
'Yes', then the data is cleared, if 'No' then the second message box appears
telling them to fill out the rest of their 'Goals'. Here is the code I have
now:

Private Sub have_goals_AfterUpdate()
Dim blnEnable As Boolean
blnEnable = (Me.have_goals.Value <> False)
Me.program_goal1.Enabled = blnEnable
Me.program_goal1_accomplished.Enabled = blnEnable
Me.program_goal2.Enabled = blnEnable
Me.program_goal2_accomplished.Enabled = blnEnable
Me.program_goal3.Enabled = blnEnable
Me.program_goal3_accomplished.Enabled = blnEnable
Me.program_goal4.Enabled = blnEnable
Me.program_goal4_accomplished.Enabled = blnEnable
Me.program_goal5.Enabled = blnEnable
Me.program_goal5_accomplished.Enabled = blnEnable
If Me.have_goals = 0 Then
MsgBox ("Un-checking this box will clear all data from all 'Goals' boxes.")
Me.program_goal1 = Null
Me.program_goal1_accomplished = Null
Me.program_goal2 = Null
Me.program_goal2_accomplished = Null
Me.program_goal3 = Null
Me.program_goal3_accomplished = Null
Me.program_goal4 = Null
Me.program_goal4_accomplished = Null
Me.program_goal5 = Null
Me.program_goal5_accomplished = Null
Else: MsgBox ("Complete all 'Goals' drop-downs and complete form.")
End If
End Sub

Can I adjust this to give the user a choice as to set the 'Goals' fields to
Nulls?

Thanks.
 
M

Mr B

Pat,

Try this code:

Private Sub have_goals_AfterUpdate()
Dim blnEnable As Boolean
Dim strMsg As String
Dim vbResponse
blnEnable = (Me.have_goals.Value <> False)
Me.program_goal1.Enabled = blnEnable
Me.program_goal1_accomplished.Enabled = blnEnable
Me.program_goal2.Enabled = blnEnable
Me.program_goal2_accomplished.Enabled = blnEnable
Me.program_goal3.Enabled = blnEnable
Me.program_goal3_accomplished.Enabled = blnEnable
Me.program_goal4.Enabled = blnEnable
Me.program_goal4_accomplished.Enabled = blnEnable
Me.program_goal5.Enabled = blnEnable
Me.program_goal5_accomplished.Enabled = blnEnable
If Me.have_goals = 0 Then
'MsgBox ("Un-checking this box will clear all data from all 'Goals' boxes.")
strMsg = "Do you want to set all of the ""Goals"" fields to Null?"
vbResponse = MsgBox(strMsg, vbYesNo + vbQuestion + vbDefaultButton1, _
"Set Goals to Null?")
If vbResonse = vbYes then
Me.program_goal1 = Null
Me.program_goal1_accomplished = Null
Me.program_goal2 = Null
Me.program_goal2_accomplished = Null
Me.program_goal3 = Null
Me.program_goal3_accomplished = Null
Me.program_goal4 = Null
Me.program_goal4_accomplished = Null
Me.program_goal5 = Null
Me.program_goal5_accomplished = Null
EndIf
Else: MsgBox ("Complete all 'Goals' drop-downs and complete form.")
End If
End Sub
 
P

Pat Dools

Worked like a charm and thank you!

Mr B said:
Pat,

Try this code:

Private Sub have_goals_AfterUpdate()
Dim blnEnable As Boolean
Dim strMsg As String
Dim vbResponse
blnEnable = (Me.have_goals.Value <> False)
Me.program_goal1.Enabled = blnEnable
Me.program_goal1_accomplished.Enabled = blnEnable
Me.program_goal2.Enabled = blnEnable
Me.program_goal2_accomplished.Enabled = blnEnable
Me.program_goal3.Enabled = blnEnable
Me.program_goal3_accomplished.Enabled = blnEnable
Me.program_goal4.Enabled = blnEnable
Me.program_goal4_accomplished.Enabled = blnEnable
Me.program_goal5.Enabled = blnEnable
Me.program_goal5_accomplished.Enabled = blnEnable
If Me.have_goals = 0 Then
'MsgBox ("Un-checking this box will clear all data from all 'Goals' boxes.")
strMsg = "Do you want to set all of the ""Goals"" fields to Null?"
vbResponse = MsgBox(strMsg, vbYesNo + vbQuestion + vbDefaultButton1, _
"Set Goals to Null?")
If vbResonse = vbYes then
Me.program_goal1 = Null
Me.program_goal1_accomplished = Null
Me.program_goal2 = Null
Me.program_goal2_accomplished = Null
Me.program_goal3 = Null
Me.program_goal3_accomplished = Null
Me.program_goal4 = Null
Me.program_goal4_accomplished = Null
Me.program_goal5 = Null
Me.program_goal5_accomplished = Null
EndIf
Else: MsgBox ("Complete all 'Goals' drop-downs and complete form.")
End If
End Sub

--
HTH

Mr B
askdoctoraccess dot com
 
Top