ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Returning focus to a user form after getting message box response (https://www.excelbanter.com/excel-programming/392754-returning-focus-user-form-after-getting-message-box-response.html)

Capt. Bangs

Returning focus to a user form after getting message box response
 
I have created a user form, and I'm at the stage where I'm programming the
data entry validation. I'm getting the message box to display when the user
hasn't enter what was expected, but then I can't get the code to return the
focus to the form itself to allow the user to correct the data entry. Any
suggestions?

Thanks!

Mike

Returning focus to a user form after getting message box response
 
Lets see your code then maybe we can help

"Capt. Bangs" wrote:

I have created a user form, and I'm at the stage where I'm programming the
data entry validation. I'm getting the message box to display when the user
hasn't enter what was expected, but then I can't get the code to return the
focus to the form itself to allow the user to correct the data entry. Any
suggestions?

Thanks!


Capt. Bangs

Returning focus to a user form after getting message box respo
 
This probably isn't very elegant: I'm a newbie. But I appreciate your offer
of help.

GoodData = False 'ensures that the loop starts

Do Until GoodData
If txtUserEmail.Value Like "*_*" Then 'checks to make
sure that the user's name is in the form "firstname_lastname"
GoodData = True
Else
If txtUserEmail.Value Like "* *" Then 'if the e-mail
address is missing the underscore
txtUserEmail.Value = LTrim(txtUserEmail.Value)
txtUserEmail.Value = Replace(txtUserEmail.Value, " ", "_")
'the program replaces a space with an underscore
GoodData = True
Else
If txtUserEmail.Value = "" Then 'if the user has not
entered a name in the text box
Dim Answer As VbMsgBoxResult
Answer = MsgBox("You have not entered your e-mail
address.", vbOKCancel)
If Answer = 2 Then
Exit Function
End If
Else
If Answer = 1 Then
txtUserEmail.SetFocus
End If
End If
End If
End If
Loop

"Mike" wrote:

Lets see your code then maybe we can help

"Capt. Bangs" wrote:

I have created a user form, and I'm at the stage where I'm programming the
data entry validation. I'm getting the message box to display when the user
hasn't enter what was expected, but then I can't get the code to return the
focus to the form itself to allow the user to correct the data entry. Any
suggestions?

Thanks!



All times are GMT +1. The time now is 07:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com