Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box Event

Status
Not open for further replies.

mar050703

Technical User
Aug 3, 2007
99
GB
I have the following Code:
Code:
Private Sub TxtCC_AfterUpdate()

If Not IsNumeric(TxtCC.Value) Then
    MsgBox "Only Numbers Please"
    Cancel = True
    End If

With TxtCC
    If (Len(.Value) <> 4) Then
    MsgBox "Only 4 Numbers Allowed"
    Cancel = True
    End If
End With
End Sub

However this only seems to work when the rest of the code has run, and therefore updated the spreadsheet with the data.

I need this piece of code to run, if the textbox looses focus, please could someone tell me what the event is I require.

I have tried TxtCC_Change, but this happens as soon as an entry is made, which obviously is not helpful.

Many Thanks
 
How about the BeforeUpdate() event?

Beir bua agus beannacht!
 
hi,

What kind of Textbox control? MS Forms, ActiveX? I'm guessing the latter.

Is this Textbox placed on the sheet?

Why not use a Data > Validation control? You could build the numeric requirement right into the DV format.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
genomon

Thanks, but this seems to do the same.

I know it is a daft question, but does the code need to be before the main code that runs?

Do I need any other info for this event?

Thanks
 
For the first part you may use [tt]TxtCC_KeyPress[/tt] instead, and prevent anything else but the Numbers to be typed.

Second part: do you want 4 digits? No more, no less?
Text box has MaxLength Property, set it to 4

Have fun.

---- Andy
 
Hi All

No worries I was being daft. Before Update did work.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top