View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
MrRadish MrRadish is offline
external usenet poster
 
Posts: 3
Default Type mismatch error

If they are both textboxes, then you access the Text property of both:

Sub UserInputCheck()
frmFacil.Hide
sFacilNameUI = frmFacil.tbFacilName.Text
On Error Resume Next
lFacilRowsUI = frmFacil.tbFacilRows.Text
On Error GoTo 0
If sFacilNameUI = "" Or lFacilRowsUI = "" Then <------TYPE MISMATCH ERROR
MsgBox "Please enter a both a Facility Name and" & Chr(10) & _
"the number of clients served!", vbOKOnly
Call GetFacilName
End If

End Sub

If you want to ensure that the number of clients is a positive number (for
example), try this:


Sub UserInputCheck()
frmFacil.Hide
sFacilNameUI = frmFacil.tbFacilName.Text
On Error Resume Next
sFacilRowsUI = frmFacil.tbFacilRows.Text
if IsNumeric(sFacilRowsUI) then lFacilRowsUI=CInt(lFacilRowsUI) else
lFacilRowsUI=0
On Error GoTo 0
If (sFacilNameUI = "") Or (lFacilRowsUI < 1) Then <------TYPE MISMATCH ERROR
MsgBox "Please enter a both a Facility Name and" & Chr(10) & _
"the number of clients served!", vbOKOnly
Call GetFacilName
End If
End Sub

"salgud" wrote:

The following code tests if the user has input both pieces of data before
proceding with the program. But I'm getting a Type Mismatch error on the IF
test.

Sub UserInputCheck()
frmFacil.Hide
sFacilNameUI = frmFacil.tbFacilName.Text
On Error Resume Next
lFacilRowsUI = frmFacil.tbFacilRows.Value
On Error GoTo 0
If sFacilNameUI = "" Or lFacilRowsUI = "" Then <------TYPE MISMATCH ERROR
MsgBox "Please enter a both a Facility Name and" & Chr(10) & _
"the number of clients served!", vbOKOnly
Call GetFacilName
End If

End Sub

How do I test for no entry on the lFacilRowsUI variable?