Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Numeric data on forms

Hi,

I am designing a form where I have some textboxes where I
want the user to enter numeric value (with or without
decimals).

since the textbox does not have properties to restrict
input data to only valid numbers, how do I do the
following:

(a) efficiently ensure that the data entered is a valid
number
(b) save the entered value (which is in text format) to a
spreadsheet cell in the format of a number

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Numeric data on forms

Hi

create a macro for the keypress event of your text box
like

private sub textbox1_KeyPress(KeyAscii as integer)
KeyAscii = textNumericOnly(KeyAscii)
end sub


Function textNumericOnly(KeyAscii as integer)

if KeyAscii = 8 or KeyAscii = 9 then
'TAB key or backspace
textNumericOnly = KeyAscii
exit function
end if

if KeyAscii < 48 or KeyAscii 57 then
textNumericOnly = 0
exit function
end if
textNumericOnly = KeyAscii
End Function


Richard Daniels
-----Original Message-----
Hi,

I am designing a form where I have some textboxes where

I
want the user to enter numeric value (with or without
decimals).

since the textbox does not have properties to restrict
input data to only valid numbers, how do I do the
following:

(a) efficiently ensure that the data entered is a valid
number
(b) save the entered value (which is in text format) to

a
spreadsheet cell in the format of a number

TIA
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Numeric data on forms

I created a form with text box called TextBox1. In it's
key press event I put in the call to the function as you
have suggested. I also did a copy-paste of your function
code hereunder. And then I executed the form.

I am getting a compile error as follows:

ByRef argument type mismatch.

The line highlighted is KeyAscii = textNumericOnly
(KeyAscii)

The word highlighted is "(KeyAscii)"

Any idea what is going wrong?

TIA


-----Original Message-----
Hi

create a macro for the keypress event of your text box
like

private sub textbox1_KeyPress(KeyAscii as integer)
KeyAscii = textNumericOnly(KeyAscii)
end sub


Function textNumericOnly(KeyAscii as integer)

if KeyAscii = 8 or KeyAscii = 9 then
'TAB key or backspace
textNumericOnly = KeyAscii
exit function
end if

if KeyAscii < 48 or KeyAscii 57 then
textNumericOnly = 0
exit function
end if
textNumericOnly = KeyAscii
End Function


Richard Daniels
-----Original Message-----
Hi,

I am designing a form where I have some textboxes where

I
want the user to enter numeric value (with or without
decimals).

since the textbox does not have properties to restrict
input data to only valid numbers, how do I do the
following:

(a) efficiently ensure that the data entered is a valid
number
(b) save the entered value (which is in text format) to

a
spreadsheet cell in the format of a number

TIA
.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Numeric data on forms

No need to call a sub. Just put it in the event:

Private Sub TextBox1_KeyPress(ByVal KeyAscii _
As MSForms.ReturnInteger)
If KeyAscii = 8 Or KeyAscii = 9 Then
'TAB key or backspace
Exit Sub
End If

If KeyAscii < 48 Or KeyAscii 57 Then
KeyAscii = 0
End If
End Sub


--
Regards,
Tom Ogilvy

"L. Fuernes" wrote in message
...
I created a form with text box called TextBox1. In it's
key press event I put in the call to the function as you
have suggested. I also did a copy-paste of your function
code hereunder. And then I executed the form.

I am getting a compile error as follows:

ByRef argument type mismatch.

The line highlighted is KeyAscii = textNumericOnly
(KeyAscii)

The word highlighted is "(KeyAscii)"

Any idea what is going wrong?

TIA


-----Original Message-----
Hi

create a macro for the keypress event of your text box
like

private sub textbox1_KeyPress(KeyAscii as integer)
KeyAscii = textNumericOnly(KeyAscii)
end sub


Function textNumericOnly(KeyAscii as integer)

if KeyAscii = 8 or KeyAscii = 9 then
'TAB key or backspace
textNumericOnly = KeyAscii
exit function
end if

if KeyAscii < 48 or KeyAscii 57 then
textNumericOnly = 0
exit function
end if
textNumericOnly = KeyAscii
End Function


Richard Daniels
-----Original Message-----
Hi,

I am designing a form where I have some textboxes where

I
want the user to enter numeric value (with or without
decimals).

since the textbox does not have properties to restrict
input data to only valid numbers, how do I do the
following:

(a) efficiently ensure that the data entered is a valid
number
(b) save the entered value (which is in text format) to

a
spreadsheet cell in the format of a number

TIA
.

.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data collection - aggrating forms data ?? InOverMyHead Excel Discussion (Misc queries) 2 May 27th 09 07:23 PM
Data Forms Cydney Excel Discussion (Misc queries) 16 October 15th 08 10:06 PM
Forms and data Pat-UK New Users to Excel 1 March 12th 08 04:31 PM
Excel Data Entry Forms (Data, Worksheet) No Name Excel Discussion (Misc queries) 1 June 28th 07 10:12 PM
Using data forms slaforest Excel Discussion (Misc queries) 1 June 29th 05 08:45 PM


All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"