ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type mismatch error (https://www.excelbanter.com/excel-programming/425353-type-mismatch-error.html)

salgud

Type mismatch error
 
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?

ryguy7272

Type mismatch error
 
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---
--
RyGuy


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


MrRadish

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?


salgud

Type mismatch error
 
On Tue, 10 Mar 2009 13:11:01 -0700, ryguy7272 wrote:

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?

Tim Zych

Type mismatch error
 
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

--
Tim Zych
http://www.higherdata.com
Workbook Compare - free and pro versions

"salgud" wrote in message
.. .
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?




salgud

Type mismatch error
 
On Tue, 10 Mar 2009 13:57:52 -0700, Tim Zych wrote:

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!


All times are GMT +1. The time now is 01:50 AM.

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