This code does not execute when I am choosing no

J

Jack

Hi,
I have an Access tabbed form. There is a checkbox in tab5. Now I have a
business rule that if I move from a textbox of tab5 to tab6(tab6 is a
subform) then a MsgBox should prompt if this will affect tab6. If the answer
is yes the focus will be in tab6 after checking the check box in tab5. If the
answer is no then the focus will also be in tab6
However the checkbox should be unchecked.

I have the following code in lost focus of the textbox of tab5. Now when the
focus moves out fo textbox of tab5 I get the msgbox. However when I click no,
the code is not being executed. I am not sure why. I appreciate any help for
resolution of this issue.
CODE:
response = MsgBox("Can cause effect on other process? If Yes consider in
6d.", vbYesNo, "Confirm Yes")

If response = vbYes Then
'Make sure to make the checkbox checked
Check523.Value = True
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
Else

Debug.Print ("Right Here")
Check523.Value = False
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
End If
 
T

tina

when the
focus moves out fo textbox of tab5 I get the msgbox.

but is the control in the subform getting the focus? it's not clear whether
you're seeing the focus move to the subform control on response = vbYes, but
not on response = vbNo, or if you're not seeing the focus move to the
subform control regardless of the response.

at any rate, several suggestions: first, there's no point putting the
SetFocus command in the If statement, because you want it to run regardless.
that being the case, you can simplify the code considerably, as

response = MsgBox("Can cause effect on other process?" _
& "If Yes consider in 6d.", vbYesNo, "Confirm Yes")

Me!Check523 = (response = vbYes)
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

second, you may have to set focus to the subform first, before setting focus
to the control in the subform, as

Me![qry6DPermAction subform].SetFocus
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

third, if that doesn't work, make sure you're using the *name of the subform
container control WITHIN the mainform*, NOT the name of the subform as it
shows in the database window. those two names may be the same or different.
to get the correct subform name, open the mainform in Design view. click
*once* on the subform to select it. in the Properties box, click on the
Other tab and look at the Name property. that's the name of the subform
control that holds, or "contains", the subform form object. that's the name
you need to refer to in code.

and last, if you take care of all the above and still have no joy, try
moving the code from the textbox control's LostFocus event to its' Exit
event.

hth


Jack said:
Hi,
I have an Access tabbed form. There is a checkbox in tab5. Now I have a
business rule that if I move from a textbox of tab5 to tab6(tab6 is a
subform) then a MsgBox should prompt if this will affect tab6. If the answer
is yes the focus will be in tab6 after checking the check box in tab5. If the
answer is no then the focus will also be in tab6
However the checkbox should be unchecked.

I have the following code in lost focus of the textbox of tab5. Now when the
focus moves out fo textbox of tab5 I get the msgbox. However when I click no,
the code is not being executed. I am not sure why. I appreciate any help for
resolution of this issue.
CODE:
response = MsgBox("Can cause effect on other process? If Yes consider in
6d.", vbYesNo, "Confirm Yes")

If response = vbYes Then
'Make sure to make the checkbox checked
Check523.Value = True
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
Else

Debug.Print ("Right Here")
Check523.Value = False
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
End If
 
J

Jack

Tina,
You have been a live savior for resolution of this issue. Your code worked
perfect. Thanks for the nice explanation of the concepts and the code change.
Thanks again. Regards.

tina said:
when the
focus moves out fo textbox of tab5 I get the msgbox.

but is the control in the subform getting the focus? it's not clear whether
you're seeing the focus move to the subform control on response = vbYes, but
not on response = vbNo, or if you're not seeing the focus move to the
subform control regardless of the response.

at any rate, several suggestions: first, there's no point putting the
SetFocus command in the If statement, because you want it to run regardless.
that being the case, you can simplify the code considerably, as

response = MsgBox("Can cause effect on other process?" _
& "If Yes consider in 6d.", vbYesNo, "Confirm Yes")

Me!Check523 = (response = vbYes)
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

second, you may have to set focus to the subform first, before setting focus
to the control in the subform, as

Me![qry6DPermAction subform].SetFocus
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

third, if that doesn't work, make sure you're using the *name of the subform
container control WITHIN the mainform*, NOT the name of the subform as it
shows in the database window. those two names may be the same or different.
to get the correct subform name, open the mainform in Design view. click
*once* on the subform to select it. in the Properties box, click on the
Other tab and look at the Name property. that's the name of the subform
control that holds, or "contains", the subform form object. that's the name
you need to refer to in code.

and last, if you take care of all the above and still have no joy, try
moving the code from the textbox control's LostFocus event to its' Exit
event.

hth


Jack said:
Hi,
I have an Access tabbed form. There is a checkbox in tab5. Now I have a
business rule that if I move from a textbox of tab5 to tab6(tab6 is a
subform) then a MsgBox should prompt if this will affect tab6. If the answer
is yes the focus will be in tab6 after checking the check box in tab5. If the
answer is no then the focus will also be in tab6
However the checkbox should be unchecked.

I have the following code in lost focus of the textbox of tab5. Now when the
focus moves out fo textbox of tab5 I get the msgbox. However when I click no,
the code is not being executed. I am not sure why. I appreciate any help for
resolution of this issue.
CODE:
response = MsgBox("Can cause effect on other process? If Yes consider in
6d.", vbYesNo, "Confirm Yes")

If response = vbYes Then
'Make sure to make the checkbox checked
Check523.Value = True
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
Else

Debug.Print ("Right Here")
Check523.Value = False
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
End If
 
T

tina

you're welcome :)


Jack said:
Tina,
You have been a live savior for resolution of this issue. Your code worked
perfect. Thanks for the nice explanation of the concepts and the code change.
Thanks again. Regards.

tina said:
when the
focus moves out fo textbox of tab5 I get the msgbox.

but is the control in the subform getting the focus? it's not clear whether
you're seeing the focus move to the subform control on response = vbYes, but
not on response = vbNo, or if you're not seeing the focus move to the
subform control regardless of the response.

at any rate, several suggestions: first, there's no point putting the
SetFocus command in the If statement, because you want it to run regardless.
that being the case, you can simplify the code considerably, as

response = MsgBox("Can cause effect on other process?" _
& "If Yes consider in 6d.", vbYesNo, "Confirm Yes")

Me!Check523 = (response = vbYes)
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

second, you may have to set focus to the subform first, before setting focus
to the control in the subform, as

Me![qry6DPermAction subform].SetFocus
Me![qry6DPermAction subform].Form!txt6DPermAct1.SetFocus

third, if that doesn't work, make sure you're using the *name of the subform
container control WITHIN the mainform*, NOT the name of the subform as it
shows in the database window. those two names may be the same or different.
to get the correct subform name, open the mainform in Design view. click
*once* on the subform to select it. in the Properties box, click on the
Other tab and look at the Name property. that's the name of the subform
control that holds, or "contains", the subform form object. that's the name
you need to refer to in code.

and last, if you take care of all the above and still have no joy, try
moving the code from the textbox control's LostFocus event to its' Exit
event.

hth


Jack said:
Hi,
I have an Access tabbed form. There is a checkbox in tab5. Now I have a
business rule that if I move from a textbox of tab5 to tab6(tab6 is a
subform) then a MsgBox should prompt if this will affect tab6. If the answer
is yes the focus will be in tab6 after checking the check box in tab5.
If
the
answer is no then the focus will also be in tab6
However the checkbox should be unchecked.

I have the following code in lost focus of the textbox of tab5. Now
when
the
focus moves out fo textbox of tab5 I get the msgbox. However when I
click
no,
the code is not being executed. I am not sure why. I appreciate any
help
for
resolution of this issue.
CODE:
response = MsgBox("Can cause effect on other process? If Yes consider in
6d.", vbYesNo, "Confirm Yes")

If response = vbYes Then
'Make sure to make the checkbox checked
Check523.Value = True
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
Else

Debug.Print ("Right Here")
Check523.Value = False
Me![qry6DPermAction subform].Form.txt6DPermAct1.SetFocus
End If
 

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