ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Require user to enter numeric value in TextBox (https://www.excelbanter.com/excel-programming/443619-require-user-enter-numeric-value-textbox.html)

jeff

Require user to enter numeric value in TextBox
 
I have searched the forum for an answer to this problem, but have been
unable to find one that works for me.

I have UserForm4 with many textboxes. The problem concerns TextBox6. I
want the user to put a numeric value in TextBox6, and it cannot be
left blank.

I put this in to make sure the value is numeric only. It works fine.

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


For the other part of the problem, I tried putting this in
CommandButton1 code that will input all the TextBox data.
I added this in to make sure the user did not leave TextBox6 blank.

Private Sub CommandButton1_Click()
'OK Add this record

If TextBox6.Value = "" Then
MsgBox "There is NO Value in Textbox 6 "
TextBox6.SetFocus
Else
AddsRecord 'Sub below

End If


This works so far as to give me the message. But, it blanks out all
the textboxes the user filled out before hitting the OK button as if
it were starting over.
What I want is for all the data already entered in to be left alone,
and the focus set on TextBox6 to enter in a value. The user would do
this, then hit the OK button again, and all the data will be copied to
the sheet. I知 sure I知 almost there. Can anyone help??
Thanks
j.o.

Harald Staff[_2_]

Require user to enter numeric value in TextBox
 
Hi j.o.

Do not make nagging msgboxes. Make it impossible to click Commandbutton1
unless the form is properly filled. Like simplified

Private Sub TextBox6_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
KeyAscii = 0
End If
If TextBox6.Text = "" then
Commandbutton1.Enabled = False
Else
Commandbutton1.Enabled = True
end If
End Sub

HTH. Best wishes Harald

"jeff" wrote in message
...
I have searched the forum for an answer to this problem, but have been
unable to find one that works for me.

I have UserForm4 with many textboxes. The problem concerns TextBox6. I
want the user to put a numeric value in TextBox6, and it cannot be
left blank.

I put this in to make sure the value is numeric only. It works fine.

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


For the other part of the problem, I tried putting this in
CommandButton1 code that will input all the TextBox data.
I added this in to make sure the user did not leave TextBox6 blank.

Private Sub CommandButton1_Click()
'OK Add this record

If TextBox6.Value = "" Then
MsgBox "There is NO Value in Textbox 6 "
TextBox6.SetFocus
Else
AddsRecord 'Sub below

End If


This works so far as to give me the message. But, it blanks out all
the textboxes the user filled out before hitting the OK button as if
it were starting over.
What I want is for all the data already entered in to be left alone,
and the focus set on TextBox6 to enter in a value. The user would do
this, then hit the OK button again, and all the data will be copied to
the sheet. I知 sure I知 almost there. Can anyone help??
Thanks
j.o.


jeff

Require user to enter numeric value in TextBox
 
On Sep 16, 10:04*am, "Harald Staff" wrote:
Hi j.o.

Do not make nagging msgboxes. Make it impossible to click Commandbutton1
unless the form is properly filled. Like simplified

Private Sub TextBox6_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
*If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
* *KeyAscii = 0
*End If
If TextBox6.Text = "" then
* * Commandbutton1.Enabled = False
Else
* * Commandbutton1.Enabled = True
end If
End Sub

HTH. Best wishes Harald

"jeff" wrote in message

...
I have searched the forum for an answer to this problem, but have been
unable to find one that works for me.

I have UserForm4 with many textboxes. The problem concerns TextBox6. I
want the user to put a numeric value in TextBox6, and it cannot be
left blank.

I put this in to make sure the value is numeric only. It works fine.

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

For the other part of the problem, *I tried putting this in
CommandButton1 code that will input all the TextBox data.
I added this in to make sure the user did not leave TextBox6 blank.

Private Sub CommandButton1_Click()
'OK Add this record

If TextBox6.Value = "" Then
MsgBox "There is NO Value in Textbox 6 "
TextBox6.SetFocus
Else
AddsRecord * 'Sub below

End If

This works so far as to give me the message. But, it blanks out all
the textboxes the user filled out before hitting the OK button as if
it were starting over.
What I want is for all the data already entered in to be left alone,
and the focus set on TextBox6 to enter in a value. The user would do
this, then hit the OK button again, and all the data will be copied to
the sheet. I知 sure I知 almost there. Can anyone help??
Thanks
j.o.


Thanks Harald. I appreciate your prompt reply. The code you gave me
works. The only thing more that would want would be to let the user
know why the OK button was not available....... that he needed to fill
in that textbox. But, I'll work around that.
Thanks again.
j.o.

jeff

Require user to enter numeric value in TextBox
 
On Sep 16, 10:04*am, "Harald Staff" wrote:
Hi j.o.

Do not make nagging msgboxes. Make it impossible to click Commandbutton1
unless the form is properly filled. Like simplified

Private Sub TextBox6_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
*If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
* *KeyAscii = 0
*End If
If TextBox6.Text = "" then
* * Commandbutton1.Enabled = False
Else
* * Commandbutton1.Enabled = True
end If
End Sub

HTH. Best wishes Harald

"jeff" wrote in message

...
I have searched the forum for an answer to this problem, but have been
unable to find one that works for me.

I have UserForm4 with many textboxes. The problem concerns TextBox6. I
want the user to put a numeric value in TextBox6, and it cannot be
left blank.

I put this in to make sure the value is numeric only. It works fine.

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

For the other part of the problem, *I tried putting this in
CommandButton1 code that will input all the TextBox data.
I added this in to make sure the user did not leave TextBox6 blank.

Private Sub CommandButton1_Click()
'OK Add this record

If TextBox6.Value = "" Then
MsgBox "There is NO Value in Textbox 6 "
TextBox6.SetFocus
Else
AddsRecord * 'Sub below

End If

This works so far as to give me the message. But, it blanks out all
the textboxes the user filled out before hitting the OK button as if
it were starting over.
What I want is for all the data already entered in to be left alone,
and the focus set on TextBox6 to enter in a value. The user would do
this, then hit the OK button again, and all the data will be copied to
the sheet. I知 sure I知 almost there. Can anyone help??
Thanks
j.o.


First off, thanks for your prompt reply.
I tried this, and if you enter an alpha character in TextBox6, then
the OK button is unavailable. That part is good.
However, if nothing is entered in the box, the user can use the OK
button, and the record is saved as before. I would like for the user
to NOT be able to continue without entering a number in this box.
If you have another idea on how to get to this, I would appreciate it.
Thanks again,
j.o.

Harald Staff[_2_]

Require user to enter numeric value in TextBox
 
Disable the button from the very beginnig. In design time, or in the
userform_initialize event:

Commandbutton1.Enabled = False




All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com