Userform TextBox

G

Guest

Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text > ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie
 
G

Guest

You need to change TextName.Text it is a string. I think you want is
val(TextName.txt) which will convert the number which is a string to an
actual numnber.
 
B

Bob Phillips

Try

If CDbl(TextName.Text) > ActiveCell.Offset(-1, 0) Then


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Bob Phillips said:
Try

If CDbl(TextName.Text) > ActiveCell.Offset(-1, 0) Then


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Thanks to Both Joel & Bob,

Bob ,

If CDbl(TextName.Text) > ActiveCell.Offset(-1, 0) Then

What does CDbl actually do?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top