Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

userform - Textbox Data validation via

  Asked By: Lulie    Date: Sep 01    Category: MS Office    Views: 1615
  

I have this problem of validating data in textbox(via userform XL
2000 with VBA(VB)6)

code]MsgBox("Please enter valid US Number.", vbOKOnly) = vbOK

Comes up with error message "LH side must have variant or object"

Here it is

Private Sub btnOK_Click()
'To enter US data & show updated calculations


Dim USNo As Integer 'From US # Textbox
Dim DateAchvd As String 'From US date achvd textbox
USNo = Int(txtUSNo.Value)
DateAchvd = txtDateAchvd.Value

'Ensure US No is enetred
If Not USNo <> "" And USNo > 56 And USNo < 20600 Then
ResultUS = MsgBox("Please enter valid US Number.", vbOKOnly)
If ResultUS = vbOK Then
txtUSNo.Value = ""
txtUSNo.SetFocus
End If

'Ensure date "dd/mm" is entered
ElseIf Not txtDateAchvd.Value <> " " Then
ResultDate = MsgBox("Please enter valid Date Format", vbOKOnly)
If ResultDate = vbOK Then
txtDateAchvd.Value = ""
txtDateAchvd.SetFocus
End If
End If
'Make sure US Prgrss is active
Sheets("US Prgss").Activate

'Find the cell with the US selected
Range("T6:CZ6").Select
Selection.Find(What:=USNo, After:=ActiveCell).Activate
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = DateAchvd
'ActiveCell.Offset(1, 0).Select
'ActiveCell.FormulaR1C1 = DateAchvd

txtUSNo.Value = ""
txtDateAchvd.Value = ""
ActiveCell.Range("C7").Activate
End Sub

I get an error message on the 1st "IF Not" line of code "Data
Mismatch Error 13" !!!!!

So no doubt I would get on the second MsgBox too!

Can't belive that this is so difficult!!!

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Stacy Cunningham     Answered On: Sep 01

You have the USno as an integer  Dim USNo As Integer but you are
testing for "".

You could set the variable to a variant which should get you going, or
you could test for "" in the text box then change the value to an
integer.

USno = CInt(txtUSNo.text)

 
Didn't find what you were looking for? Find more on userform - Textbox Data validation via Or get search suggestion and latest updates.




Tagged: