Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch on variant field type

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

Why am I getting a type mismatch error for this line
Code:
If myControlInfo <> "" Then

the variable myControlInfo is defined as follows
Code:
Function SaveToAudit(ByVal frm As Form, ByVal lContactID As Long, ByVal sTable As String, [b]ByVal myControlInfo As Variant[/b])

a variant means it can be a string doesn't it?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Just a hunch but try dropping the ByVal from your declaration of myControlInfo - Byval is not best used for String types anyway, plus if it's going to be a string declare it is a String, not a Variant...

[pc2]
 
byVal means you are passing in the actual value of the variable instead of a reference of it, so shouldn't affect your conditional test.

what is more likely is that your variant value isn't a string, so you're testing 2 different types...

put a cstr() around the variant...


--------------------
Procrastinate Now!
 
Another thing to try:
If Trim(myControlInfo & "") <> "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
it's ok I was having a mad 5 minutes, the variable was an array simply changing it to
Code:
If myControlInfo(0) <> "" Then
works fine!

it was this line giving me the jip originaly
Code:
For a = 0 To UBound(myControlInfo)

I guess an array that equals "Empty" errors as I take it UBound = NULL if (0) is not defined/used

So needed to nest an IF condition around the the loop.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top