Type mismatch error

S

salgud

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?
 
R

ryguy7272

Is 'lFacilRowsUI' text or Value? If it is Value, I think if it is Text, you
need something like this:
"'" Or lFacilRowsUI = "'"
That is a apostrophe between the quotes.
If it is Value, i think you need something like this:
" Or lFacilRowsUI = "

HTH,
Ryan---
 
M

MrRadish

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
 
S

salgud

Is 'lFacilRowsUI' text or Value? If it is Value, I think if it is Text, you
need something like this:
"'" Or lFacilRowsUI = "'"
That is a apostrophe between the quotes.
If it is Value, i think you need something like this:
" Or lFacilRowsUI = "

HTH,
Ryan---

Thanks for your reply, Ryan, but it doesn't make much sense. "If it is
Vaue, I think if it is Text" confuses me. And the quotes in my post are not
around "or lFacilRowsUI", they indicate testing for blank values in either
field, as in sFacilNameUI = "" and lFacilRowsUI = "".

BTW, I should have said that lFacilRowsUI is long, and sFacilNameUI is a
string. Does anyone have any other suggestions?
 
T

Tim Zych

Is lFacilRowsUI declared as a Long?

If so evaluating it as a string will cause that error.

If lFacilRowsUI has not been assigned a value, it will default to 0 if
declared as a Long.

One way to fix it:

If sFacilNameUI = "" Or lFacilRowsUI = 0

But if 0 is an acceptable entry another approach is needed such as:

If frmFacil.tbFacilName.Text = "" And frmFacil.tbFacilRows.Text = "" Then
MsgBox "Please enter a both a Facility ...."
'...
End If
 
S

salgud

Is lFacilRowsUI declared as a Long?

If so evaluating it as a string will cause that error.

If lFacilRowsUI has not been assigned a value, it will default to 0 if
declared as a Long.

One way to fix it:

If sFacilNameUI = "" Or lFacilRowsUI = 0

But if 0 is an acceptable entry another approach is needed such as:

If frmFacil.tbFacilName.Text = "" And frmFacil.tbFacilRows.Text = "" Then
MsgBox "Please enter a both a Facility ...."
'...
End If

Thanks, Tim!
 

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