B
Bryan Hughes
Hello,
How do you cancel exit form an unbound textbox if a condition is not meet
from a called module?
I have a unbound subform that users enter phone numbers into, on exiting
event a module is called that checks to see if the correct phone number
length has been entered. If it has then it exits sub, if not it gives
message.
If condition is not meet how do I prevent users from exiting field?
(Everyting is declared at top of module)
Here is OnExit event:
**************************************
'Check home phone #
Private Sub txtHP_Exit(Cancel As Integer)
On Error GoTo ErrorHandler
strPhone = Nz(Me![txtHP].Value, "")
'If nothing entered move to cell phone #
'Else check to see if home phone is complete
If strPhone = "" Then
Me.txtCP.SetFocus
Exit Sub
Else
intLength = Len(strPhone)
Call CheckPhone(strPhone, intLength)
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " _
& Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
********************************
Here is called module sub:
********************************
'Check Phone length
Public Sub CheckPhone(strPhone As String, intLength As Integer)
On Error GoTo ErrorHandler
Select Case intLength
Case 10
Exit Sub
Case 14
If strPhone Like "(###) ###-####" Then
'MsgBox "14 and formatted correctly"
Exit Sub
Else
'MsgBox "14 and not formatted correctly"
MsgBox "Phone numbers must have Area Code and Number!", _
vbExclamation, "Message"
End If
Case Else
MsgBox "Phone numbers must have Area Code and Number!", _
vbExclamation, "Message"
Exit Sub
End Select
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
-Please help
-Bryan
How do you cancel exit form an unbound textbox if a condition is not meet
from a called module?
I have a unbound subform that users enter phone numbers into, on exiting
event a module is called that checks to see if the correct phone number
length has been entered. If it has then it exits sub, if not it gives
message.
If condition is not meet how do I prevent users from exiting field?
(Everyting is declared at top of module)
Here is OnExit event:
**************************************
'Check home phone #
Private Sub txtHP_Exit(Cancel As Integer)
On Error GoTo ErrorHandler
strPhone = Nz(Me![txtHP].Value, "")
'If nothing entered move to cell phone #
'Else check to see if home phone is complete
If strPhone = "" Then
Me.txtCP.SetFocus
Exit Sub
Else
intLength = Len(strPhone)
Call CheckPhone(strPhone, intLength)
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " _
& Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
********************************
Here is called module sub:
********************************
'Check Phone length
Public Sub CheckPhone(strPhone As String, intLength As Integer)
On Error GoTo ErrorHandler
Select Case intLength
Case 10
Exit Sub
Case 14
If strPhone Like "(###) ###-####" Then
'MsgBox "14 and formatted correctly"
Exit Sub
Else
'MsgBox "14 and not formatted correctly"
MsgBox "Phone numbers must have Area Code and Number!", _
vbExclamation, "Message"
End If
Case Else
MsgBox "Phone numbers must have Area Code and Number!", _
vbExclamation, "Message"
Exit Sub
End Select
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
-Please help
-Bryan