Setting focus on a form field

G

Guest

Hi

I have a form where all fields are required. If someone tabs moces out of
CL_KEY before entering anything, I have some code which says this...

Private Sub CL_KEY_LostFocus()
If CL_KEY.Text = "" Then
MsgBox "The CLIENT KEY MUST be filled in.", vbCritical + vbOKOnly
End If
End Sub

However, As well as the above message, I would like the focus to go back to
CL_KEY once OK has been pressed on the message box. I have tried various
bits of code but I keep getting error messages of varying descriptions.

Any ideas how I can achieve this as I will be using this on all fields of
which there are 9.

Thanks in advance

Malcolm
 
O

Ofer Cohen

Use the OnExit event instead on the LostFocus, in there you can use the
Cancel, to stop the exit from the field

If Trim(CL_KEY.Text & "") = "" Then
MsgBox "The CLIENT KEY MUST be filled in.", vbCritical + vbOKOnly
Cancel = True ' will stop the exit
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

Similar Threads


Top