Why this is not returning to the previous control

  • Thread starter Thread starter Tru Dixon
  • Start date Start date
T

Tru Dixon

I am calling this function from the OnExit_Event
=RequiredField([FirstName])
The problem I am having is: When the user selects "Yes"
from the Prompt MSGBox. The cursor is not returned to the
textbox that prompted the message.

Function RequiredField(FieldInfo As Variant) As Variant
'confirms if user wants to leave field blank
Dim Response As Integer
Dim Cancel As Integer

If IsNull(FieldInfo) Then
Response = MsgBox("It is recommended that you
complete this field." & Chr(13) & Chr(10) & _
"Do you wish to do that now?", vbYesNo +
vbExclamation, "Required Field!")
If Response = vbNo Then
Cancel = False
Else
Cancel = True
End If
End If
End Function
 
You are assuming that the Cancel in your fn RequiredField
() is the same as the Cancel argument in the Sub
Control_Exit Event Procedure. They are different
entities. You Cancel only exists in your function and
does get passed back to the Event Procedure.

Actually, I am not even sure that you use Event Procedure
from what you posted.

HTH
Van T. Dinh
MVP (Access)
 
try using
Else
Cancel = True
field.setfocus
End If

alternately when you call this from the on exitevent,

use cancel = requiredfield(fieldName)

and change your code to be
If Response = vbNo Then
RequiredField= False
Else
RequiredField= True
End If


Tru Dixon said:
I am calling this function from the OnExit_Event
=RequiredField([FirstName])
The problem I am having is: When the user selects "Yes"
from the Prompt MSGBox. The cursor is not returned to the
textbox that prompted the message.

Function RequiredField(FieldInfo As Variant) As Variant
'confirms if user wants to leave field blank
Dim Response As Integer
Dim Cancel As Integer

If IsNull(FieldInfo) Then
Response = MsgBox("It is recommended that you
complete this field." & Chr(13) & Chr(10) & _
"Do you wish to do that now?", vbYesNo +
vbExclamation, "Required Field!")
If Response = vbNo Then
Cancel = False
Else
Cancel = True
End If
End If
End Function
 

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

Back
Top