PDA

View Full Version : Solved: Exit behaviour for last field in a frame



devolved
05-05-2010, 01:35 PM
Hi.

I have a large number of text boxes on a form, split into eight separate frames. I've got code to handle input validation for each textbox, ensuring that only numeric data is entered. It is triggered in the Exit event for the control. This is working fine for every textbox within a frame *except* the very last one, in which case no error message will appear and focus moves to the first box of the next frame. It seems almost as if leaving the very last textbox of a frame is simply not triggering the Exit event at all.

Here's the code I'm using:


Private Sub txtInput1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If VerifyNumbers(frmInputSession.txtInput1) = False Then
Cancel = True
End If

End Sub

Function VerifyNumbers(Ctrl As Object) As Boolean

VerifyNumbers = True

If Ctrl.Name Like "txtInput*" Then
With Ctrl
If Not IsNumeric(.Value) And .Value <> "" Then
MsgBox "Sorry, only numbers allowed."
.Value = ""
VerifyNumbers = False
End If
End With
End If

End Function

So, just to reiterate, this is functioning perfectly fine for every textbox control on the form, except those that happen to be the last one of a frame. So that means of 34 textboxes in 8 frames, only 26 work properly.

Oddly enough though, code seems to execute when I move back to that control with a mouse click.

Aside from the control names (txtInput*), the code is identical for every one of those 34.

Can anyone tell me what's up with this?

Thanks.

devolved
05-06-2010, 01:17 PM
Never mind.

Removed the frames. Works fine now.

RonMcK3
05-06-2010, 01:39 PM
devolved,

If this is now closed, please mark it that way. Click on the down arrow by Thread Tools in the tool bar and click Mark Solved and then the Perform Action button.

Thanks,