Un-explained Type mismatch

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I get a type mismatch when I encounter
this statement:

If Len(HOHA(1)) > 0 And HOHA(2) Then Me.tbLn7 = "Cell(1) " & HOHA(1)

The highlighted area in Debug is:

If Len(HOHA(1)) > 0 And HOHA(2) Then

HOHA is a string array and the current value
of HOHA(1) is a zero-length string, "". And,
HOHA(2) is a True/False value and is currently
false.

Len(HOHA(1)) > 0 is false, so I was expecting
an evaluation of two T/F expressions.

Apparently VBA is not treating the expressions as
I expect????

Bill
 
Bill

Have you tried "coercing" these expressions into something Access would
treat as, say, a boolean? You might want to look into the CBool()
function...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Bill,
what happens if you re-write it like this:

If HOHA(2) = True Then
If Len(HOHA(1)) > 0 Then
Me.tbLn7 = "Cell(1) " & HOHA(1)
End If
End If

Jeanette Cunningham
 
CBool by itself didn't do the trick, but treating
HOHA(2) as a T/F in and of itself turned out
to be the problem. I had to replace it with

If Len(HOHA(1)) > 0 And HOHA(2) = True Then

Thanks,
Bill
 
Bill said:
CBool by itself didn't do the trick, but treating
HOHA(2) as a T/F in and of itself turned out
to be the problem. I had to replace it with

If Len(HOHA(1)) > 0 And HOHA(2) = True Then


Sounds like an issue involving the precedence of the operators.
 
I haven't used arrays in years, and I'm trying to understand this; maybe
someone could explain! If HOHA is a string array, how can one member of the
array, HOHA(1) be a string, while another member, HOHA(2) is apparently
Boolean rather than a string?

A string could be equal to "True," but I wouldn't think that a string could
be equal to True (without the quotation marks)

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
In this particular case, the HOHA(2) originates from
a table field with the Yes/No formatting attributes. As
such it has a zero or one value. When the array was
loaded, it was done with a Split function into an
the un-dimensioned array HOHA.

Dim HOHA() as string

The expression being split was returned by a function
that had created the string by gathering five fields from
a SQL Select, 3 of which are strings and the other
two are YES/NO. This likely wouldn't work if MS
had implemented YES/NO in such a way that the field
could be null.

I hope this helps.

Bill
 
Thanks for the reply!

Linq
In this particular case, the HOHA(2) originates from
a table field with the Yes/No formatting attributes. As
such it has a zero or one value. When the array was
loaded, it was done with a Split function into an
the un-dimensioned array HOHA.

Dim HOHA() as string

The expression being split was returned by a function
that had created the string by gathering five fields from
a SQL Select, 3 of which are strings and the other
two are YES/NO. This likely wouldn't work if MS
had implemented YES/NO in such a way that the field
could be null.

I hope this helps.

Bill
I haven't used arrays in years, and I'm trying to understand this; maybe
someone could explain! If HOHA is a string array, how can one member of
[quoted text clipped - 5 lines]
could
be equal to True (without the quotation marks)

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
Back
Top