Question : VBA - Pause after SetFocus

I have the following code

Private Sub ExitCheck()
On Error GoTo PROC_ERR
     If Me.txtbox1.Value = "Enter here" Then
          Me.txtbox1.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 Me.txtbox1.SetFocus is called, there is no pause for the user to input new text in the textbox. The only way I can do that is to call GoTo PROC_EXIT. In a command button click event programmed to close a form.  it works fine with the GoTo PROC_EXIT after the SetFocus. I am trying to match the same code to the Form_Close event and it will not work in that event when the above sub is called. It will close the form without letting the user input new text in the text boxes.

Answer : VBA - Pause after SetFocus

Use the Form_Unload event instead. Then you can cancel the unload.

Lee

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Private Sub Form_Unload(Cancel As Integer)

    If txtbox1 = "Enter here" Then
       MsgBox "Please enter data into first textbox"
       txtbox1.SetFocus
       Cancel = True
    ElseIf txtbox2 = "Enter here" Then
       MsgBox "Please enter data into second textbox"
       txtbox2.SetFocus
       Cancel = True
    End If

End Sub
Random Solutions  
 
programming4us programming4us