Pausing after SetFocus

jbotts

Registered User.
Local time
Today, 02:20
Joined
Jun 8, 2009
Messages
22
I have the following code:

Private Sub ExitCheck()
On Error GoTo PROC_ERR

If Me.txtbox.Value = "Enter here" Then
Me.txtbox.SetFocus
End If

If Me.txtbox2.Value = "Enter here" Then
Me.txtbox2.SetFocus
End If

PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub

When the sub is called the first Me.txtbox.SetFocus does not pause for the user in enter new text. Is there a way for the first SetFocus to pause for the user to enter text without calling GoTo PROC_EXIT?
 
If PROC_EXIT is being called then that means you're code is throwing an error. Did you disable any of the textboxes in code or otherwise?
 
Actually your error label is PROC_ERR. What are you actually trying to do?
 
When closing a form, I am trying to have the user enter a value in the text box that is not the default value. The following code will work if called in a command button click event. With GoTo PROC_EXIT the cursor will be in the designated control when the sub below is called.

I am trying to match the code in the command button click event in the Form_Close method. The reason is that if the user clicks the form's close button of the control box in the right upper corner of the form, the form closes without letting the user enter new text in the designated text box, thus leaving the default value in the text box. The text boxes are all enabled = true.


This code works when called in a command button click event, but not in the Form_Close().


Private Sub ExitCheck()
On Error GoTo PROC_ERR

If Me.txtbox.Value = "Enter here" Then
Me.txtbox.SetFocus
GoTo PROC_EXIT
End If

If Me.txtbox2.Value = "Enter here" Then
Me.txtbox2.SetFocus
GoTo PROC_EXIT
End If

PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub
 
Use the UNLOAD event and set the argument of that event, Cancel, to False if the condition is met. You can't interrup the closing of a form via the close event only via the Unload event.
 
Thanks, vbaInet. That is the solution!
jbotts
 

Users who are viewing this thread

Back
Top Bottom