Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing Integers into Textbox
Hi All
What is the simplest method to prevent users entering a non-integer into a textbox control on a user form? TIA Cheers Nigel ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing Integers into Textbox
Nigel,
One way of doing it: Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim strTemp As String, blnFound As Boolean blnFound = False strTemp = TextBox1.Text If IsNumeric(strTemp) Then If Int(strTemp) = strTemp Then blnFound = True End If If Not blnFound Then MsgBox "Value must be an Integer", vbExclamation TextBox1.Text = "" Cancel = True End If End Sub Rob "Nigel" wrote in message ... Hi All What is the simplest method to prevent users entering a non-integer into a textbox control on a user form? TIA Cheers Nigel ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing Integers into Textbox
Nigel,
Another way is to trap on key input. This shows the way Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 48 To 57 'Nos 0 - 9 Exit Sub Case Else Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True Beep End Select End Sub Typing anything other than 0-9 returns a beep. You could easily modify this to play a sound, or throw up a message. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Rob van Gelder" wrote in message ... Nigel, One way of doing it: Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim strTemp As String, blnFound As Boolean blnFound = False strTemp = TextBox1.Text If IsNumeric(strTemp) Then If Int(strTemp) = strTemp Then blnFound = True End If If Not blnFound Then MsgBox "Value must be an Integer", vbExclamation TextBox1.Text = "" Cancel = True End If End Sub Rob "Nigel" wrote in message ... Hi All What is the simplest method to prevent users entering a non-integer into a textbox control on a user form? TIA Cheers Nigel ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing Integers into Textbox
Thanks for the suggestions.
I need to allow any integer value from 1 to n; where n is in the range 1 to 9999, so the general purpose approach would seem to require taking the integer value and testing against the input as Rob suggested. I can cope with non numeric input since I take the Val(TextBox1.Value). I am also using the TextBox update event to take the entry just made. Can't see any problems with this at present Thanks again Cheers Nigel "Bob Phillips" wrote in message ... Nigel, Another way is to trap on key input. This shows the way Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 48 To 57 'Nos 0 - 9 Exit Sub Case Else Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True Beep End Select End Sub Typing anything other than 0-9 returns a beep. You could easily modify this to play a sound, or throw up a message. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Rob van Gelder" wrote in message ... Nigel, One way of doing it: Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim strTemp As String, blnFound As Boolean blnFound = False strTemp = TextBox1.Text If IsNumeric(strTemp) Then If Int(strTemp) = strTemp Then blnFound = True End If If Not blnFound Then MsgBox "Value must be an Integer", vbExclamation TextBox1.Text = "" Cancel = True End If End Sub Rob "Nigel" wrote in message ... Hi All What is the simplest method to prevent users entering a non-integer into a textbox control on a user form? TIA Cheers Nigel ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing Integers into Textbox
Yep, that's a better way!
Need to test for the minus character as well. "Bob Phillips" wrote in message ... Nigel, Another way is to trap on key input. This shows the way Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 48 To 57 'Nos 0 - 9 Exit Sub Case Else Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True Beep End Select End Sub Typing anything other than 0-9 returns a beep. You could easily modify this to play a sound, or throw up a message. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Rob van Gelder" wrote in message ... Nigel, One way of doing it: Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim strTemp As String, blnFound As Boolean blnFound = False strTemp = TextBox1.Text If IsNumeric(strTemp) Then If Int(strTemp) = strTemp Then blnFound = True End If If Not blnFound Then MsgBox "Value must be an Integer", vbExclamation TextBox1.Text = "" Cancel = True End If End Sub Rob "Nigel" wrote in message ... Hi All What is the simplest method to prevent users entering a non-integer into a textbox control on a user form? TIA Cheers Nigel ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
decrease integers to zero | Excel Worksheet Functions | |||
Calculate Textbox value based on another textbox value.doc | Excel Discussion (Misc queries) | |||
Calculate Textbox value based on another textbox value | Excel Discussion (Misc queries) | |||
A list of Consecutive Integers, can I search for missing integers | Excel Worksheet Functions | |||
UserForm TextBox to ActiveSheet TextBox over 256 characters | Excel Programming |