Wierd Msgbox action - Can anyone see the fault?

H

harpscardiff

I'm having a problem with my validation I set. Basically if policy
number textbox is not 8 digits long then msgbox retry. It should let me
go back to the textbox and update . The problem I am having is, I click
retry and it moves to next textbox and I dont know why :confused:

Below is the code:

Any ideas what is wrong?

Thanks



Code:
--------------------

Public Sub txtpolicynumber_AfterUpdate()
Dim Policynumber, Msg, Style, Title, Response, CheckRetry As String


Msg = "Invalid Entry. Must be 8 digits long"
Style = vbRetry + vbCritical
Title = "Data Validation"
Response = Msgbox(Msg, Style, Title)
CheckRetry = vbRetry
Policynumber = txtpolicynumber.Value


If Len(Policynumber) <> 8 Then
Response = Msgbox(Msg, Style, Title)
txtpolicynumber.SetFocus
End If

End Sub
 
T

Tom Ogilvy

because the movement out of the textbox is still pending.

Try using the Exit event:

Public Sub txtpolicynumber_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Policynumber, Msg, Style, Title, Response, CheckRetry As String


Msg = "Invalid Entry. Must be 8 digits long"
Style = vbRetry + vbCritical
Title = "Data Validation"
Response = Msgbox(Msg, Style, Title)
CheckRetry = vbRetry
Policynumber = txtpolicynumber.Value


If Len(Policynumber) <> 8 Then
Response = Msgbox(Msg, Style, Title)
'txtpolicynumber.SetFocus
Cancel = True
End If

End Sub

--
Regards,
Tom Ogilvy


"harpscardiff" <[email protected]>
wrote in message
news:[email protected]...
 
H

harpscardiff

Thanks for your reply Tom. I understand what you’re saying, but th
code you added don’t work, it doesn’t prompt the user at all. Where a
before, it use to prompt the user and then continue to the next tex
box. I need it to work as you tab to the next textbox.

Thanks
 

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

Help with if elseif verification 2
how to store user responses 2
Form, SetFocus and AfterUpdate issue 2
Simple Msgbox needed 2
PLEASE HELP!! SAVE MACRO 2
SAVE AS MACRO 4
another code not working 4
Beep in a MsgBox 2

Top