decimal value in the textbox. 
Author Message
 decimal value in the textbox.

Hello Newsgroupreaders
Excel 2000

With thanks to Chip Pearson I make this code and it works good only I don't
want that it is possible to put a decimal value in the textbox.
Now for example 3,34 is possible.

Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(txtb) Then
If txtb < 1 Or txtb > 7 Then Cancel = True

End If
If Not IsNumeric(txtb) Then Cancel = True
End Sub

Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
You might try something like this:

Private Sub txtb_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
 If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
   KeyAscii = 0
 End If
End Sub

You can replace Asc("0") and Asc("9") with the actual keycode numbers.

Reagards,
Tom Ogilvy



Quote:
> Hello Newsgroupreaders
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
How about:

If IsNumeric(txtb) Then
    If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
Else
    Cancel = True
End If
If Cancel Then MsgBox "Must be an integer between 1 and 7."

Rob Rutherford



Quote:

> Hello Newsgroupreaders
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
Hi Ron,

Next to all the others, here's another one:

  If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
  Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
    ((CInt(TextBox1) - TextBox1) < 0) Xor _
    (Not IsNumeric(TextBox1)))

Just exchanging ideas here.
Perry



Quote:

> Hello Newsgroupreaders
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
  Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
    ((CInt(TextBox1) - TextBox1) < 0))
End Sub



Quote:
> Hi Ron,

> Next to all the others, here's another one:

>   If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
>   Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
>     ((CInt(TextBox1) - TextBox1) < 0) Xor _
>     (Not IsNumeric(TextBox1)))

> Just exchanging ideas here.
> Perry



> > Hello Newsgroupreaders
> > Excel 2000

> > With thanks to Chip Pearson I make this code and it works good only I
> don't
> > want that it is possible to put a decimal value in the textbox.
> > Now for example 3,34 is possible.

> > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > If IsNumeric(txtb) Then
> > If txtb < 1 Or txtb > 7 Then Cancel = True

> > End If
> > If Not IsNumeric(txtb) Then Cancel = True
> > End Sub

> > Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
Thanks all for your reply



Quote:
> Hello Newsgroupreaders
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.

Hi Rob I like your code the most but If you use the msgbox then you lost the
focus on the textbox.
Do you now a solution.

Ron



Quote:
> How about:

> If IsNumeric(txtb) Then
>     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> Else
>     Cancel = True
> End If
> If Cancel Then MsgBox "Must be an integer between 1 and 7."

> Rob Rutherford



> > Hello Newsgroupreaders
> > Excel 2000

> > With thanks to Chip Pearson I make this code and it works good only I
> don't
> > want that it is possible to put a decimal value in the textbox.
> > Now for example 3,34 is possible.

> > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > If IsNumeric(txtb) Then
> > If txtb < 1 Or txtb > 7 Then Cancel = True

> > End If
> > If Not IsNumeric(txtb) Then Cancel = True
> > End Sub

> > Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.
Ron,

I tried it in Excel 97 on a user form with a text box and a command button.
If I enter 99 in the text box and click the button the message displays and
the focus remains in the text box. How do you invoke the txtb_Exit event?

Rob Rutherford



Quote:

> Hi Rob I like your code the most but If you use the msgbox then you lost
the
> focus on the textbox.
> Do you now a solution.

> Ron



> > How about:

> > If IsNumeric(txtb) Then
> >     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> > Else
> >     Cancel = True
> > End If
> > If Cancel Then MsgBox "Must be an integer between 1 and 7."

> > Rob Rutherford



> > > Hello Newsgroupreaders
> > > Excel 2000

> > > With thanks to Chip Pearson I make this code and it works good only I
> > don't
> > > want that it is possible to put a decimal value in the textbox.
> > > Now for example 3,34 is possible.

> > > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > > If IsNumeric(txtb) Then
> > > If txtb < 1 Or txtb > 7 Then Cancel = True

> > > End If
> > > If Not IsNumeric(txtb) Then Cancel = True
> > > End Sub

> > > Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 decimal value in the textbox.

Hi Rob

I said it the wrong way maybe.
The textbox has the focus but the cursor is not in it.
So I can type somthing else before I click on the textbox.

Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(txtb) Then
    If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
Else
    Cancel = True
End If
If Cancel Then MsgBox "Must be an integer between 1 and 7."
End Sub



Quote:
> Ron,

> I tried it in Excel 97 on a user form with a text box and a command
button.
> If I enter 99 in the text box and click the button the message displays
and
> the focus remains in the text box. How do you invoke the txtb_Exit event?

> Rob Rutherford



> > Hi Rob I like your code the most but If you use the msgbox then you lost
> the
> > focus on the textbox.
> > Do you now a solution.

> > Ron



> > > How about:

> > > If IsNumeric(txtb) Then
> > >     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> > > Else
> > >     Cancel = True
> > > End If
> > > If Cancel Then MsgBox "Must be an integer between 1 and 7."

> > > Rob Rutherford



> > > > Hello Newsgroupreaders
> > > > Excel 2000

> > > > With thanks to Chip Pearson I make this code and it works good only
I
> > > don't
> > > > want that it is possible to put a decimal value in the textbox.
> > > > Now for example 3,34 is possible.

> > > > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > > > If IsNumeric(txtb) Then
> > > > If txtb < 1 Or txtb > 7 Then Cancel = True

> > > > End If
> > > > If Not IsNumeric(txtb) Then Cancel = True
> > > > End Sub

> > > > Regards Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Textbox values based on other textbox values

2. How can I change some values from decimal point to decimal comma

3. Storing Decimal Values versus Displaying Decimals ..

4. Total textbox values on a form...and have the total appear in another textbox

5. Enable a textbox after entering a value into another textbox

6. Combining Two Textbox Values into a Third Textbox

7. doing calculations in hidden textboxes and placing values in visible textboxes in form (Access 2.0)

8. How to get mainform textbox value to transfer to subform textbox

9. Assigning value to textbox if name of textbox is a variable

10. Assigning value to textbox if textbox is a variable name


 
Powered by phpBB® Forum Software © phpBB Group