Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button

A TextBox That Only accepts Numbers

You may already know that you can insert a textBox from the Control Toolbox and you will be able to type in it during a show.

This is a way to control what can be entered. I have seen many convoluted ways to achieve this but this is a concise and simple way.

Normally people use the default TextBox_OnChange method. In this example we select the KeyPress method.

Right click the textBox and 'View Code'. Use the right hand drop menu to choose 'Key Down' and the first and last code lines should insert themselves. Now add the code so that if the returned key code is 0 -9, a decimal point or ESC or Backspace the code is entered. Anything else generates code zero and does nothing.

Copy and paste to get this:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 46, 48 To 57, 8, 27, 'allow ESC and Backspace and 0-9 and point
Case Else
KeyCode = 0 'deny
End Select
End Sub


You can easily adapt to allow other inputs.

 

 

 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation