Un-explained Type mismatch

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
 
J

Jeff Boyce

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
 
J

Jeanette Cunningham

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
 
B

Bill

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
 
D

Dirk Goldgar

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.
 
L

Linq Adams via AccessMonster.com

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)
 
B

Bill

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
 
L

Linq Adams via AccessMonster.com

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)
 

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