View Full Version : Yes/No to boolean


xMax
08-07-2006, 06:46 AM
I need to know how I can get code in Visual Basic to understand a Yes/No field in a table? I would prefer using booleans, but anything is fine.

Banana
08-07-2006, 06:58 AM
VB is flexible. You can say True:False or -1:0 or even Yes:No.

True/False is more efficient, though.

xMax
08-07-2006, 07:13 AM
ok I am putting a field, enablethis = DLookUp ("candothis", "tbltable", tblname = " & cmbtblname)

enablethis is a boolean

candothis is a yes or no field
tbltable is a table
tblname is a text field in a table
cmbtblname is a text field on the form

I'm getting an error message that says "You canceled the previous operation" whenever I try to run the program. What do I do?

Banana
08-07-2006, 07:15 AM
I think the syntax is incorrect. Search forums to get right syntax.

xMax
08-07-2006, 07:18 AM
enablethis = DLookup ("candothis", "tbltable", "tblname = " & cmbtblname)

This is what it looks like. Syntax is correct (I use other DLookup commands and they work).

Pauldohert
08-07-2006, 07:28 AM
Try

enablethis = DLookup ("candothis", "tbltable", "tblname = '" & cmbtblname & "'")

since cmbtblname is a string

xMax
08-07-2006, 07:33 AM
doesn't work. I think the problem deals with the boolean statement.

Pauldohert
08-07-2006, 07:56 AM
I get that error if I don't use the ' or if I have the field names etc wrong.

Banana
08-07-2006, 11:35 AM
Now that makes sense-

If you use a string, you cannot get a null, only a zero length string, and that's not really evaluable.

If you want to keep the string, you need do something like this:

TestCriteria= Dlookup()
If Len(TestCriteria) Then EnableThis