textbox validation

  • Thread starter Thread starter Beginner
  • Start date Start date
B

Beginner

hi!
i have a multipage within a form. the multipage has
several textboxes. some of them use the values of the
others textboxes to do math thing, like adds.
everything goes wrong when the user capture characters.
how can i ensure the user to capture only numbers, integer
numbers?
tia.
 
Hi Begi,

Here is a textbox event that only allows numeric input

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57 'Nos 0 - 9
Exit Sub
Case 32 ' space
Case Else
Application.EnableEvents = False
KeyAscii = 0
Application.EnableEvents = True
Beep
End Select

End Sub

It also allows spaces, if you don't want that remove the line

Case 32 ' space

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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

Back
Top