By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

VB - Question for OpenForm Criteria

P: n/a
In " vb help" the example for OpenForm Method works fine...

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

However if I try to apply the example to my field which is a "yes or
no" it does not.

Is there some way to do it?

DoCmd.OpenForm "Employees", , ,"answer = 'yes'"

or

DoCmd.OpenForm "Employees", , ,"answer = '-1'"

Does not produce the desired results...
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Nairb wrote:
In " vb help" the example for OpenForm Method works fine...

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

However if I try to apply the example to my field which is a "yes or
no" it does not.

Is there some way to do it?

DoCmd.OpenForm "Employees", , ,"answer = 'yes'"

or

DoCmd.OpenForm "Employees", , ,"answer = '-1'"

Does not produce the desired results...

You are attempting to write the Where clause using an expression that is
for a string.
However a Yes/No field is a Boolean field
(a Number, -1 for Yes, 0 for No)
So, for Yes:
"[Answer] = -1"
Or for No:
"[Answer] = 0"
No quotes around the number.

See Access Help files regarding:
Where clause + Restrict data to a subset of records
--
Fred
Please reply only to this newsgroup.
I do not respond to personal e-mail.
Nov 12 '05 #2

P: n/a
bg***@yahoo.com (Nairb) wrote in message news:<33**************************@posting.google. com>...

DoCmd.OpenForm "Employees", , ,"answer = 'yes'"

or

DoCmd.OpenForm "Employees", , ,"answer = '-1'"

Does not produce the desired results...

Just a guess, but try this:

DoCmd.OpenForm "Employees", , ,"answer = True"

Since Booleans ("yes or no" fields) aren't strings, you don't have to
put them in quotes. They're either True or False.

When you put quotes around 'yes' it becomes the word yes, not a True
value. So when you compare the Boolean value in the answer field to a
String, you're comparing different data types and that's going to give
you an error.

Hope this makes sense,
Bill
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.