IIf statement and check boxes

R

Radhika

I am trying to create a query that uses two fileds ('VP OtherGlue on
valve/hinge', 'VROther:Extra Increased Resistance') from the same table
'tbl_TEPRecords'.
Both field are check boxes.
I want the IIf statement to check 'VP OtherGlue on valve/hinge' if
'VPOther:ExtraIncreased Resistance' is checked.

I used the following IIf statement:
VP OtherGlue on valve/hinge: IIf([VP Other:Extra Increased
Resistance]=True,True)
When I do this, I get a -1 instead of a checked check box. How do I change
my statement so that my check box is checked?

Thankyou,
Radhika
 
B

Beetle

The IIf statement is only going to return a value, not change the value
of any existing records.

If you need to change the value of existing records, you would typically
run an update query, something like;

"Update tblYourTable Set YourFirstField = True Where
YourSecondField = True"
 
J

John W. Vinson

I am trying to create a query that uses two fileds ('VP OtherGlue on
valve/hinge', 'VROther:Extra Increased Resistance') from the same table
'tbl_TEPRecords'.
Both field are check boxes.

Ummmm... no. They're not. A Checkbox is a *display and editing tool*, not a
data value. A Yes/No (True/False, checked/unchecked) field is actually stored
in your Table as a number, -1 for Yes/True/checked, 0 otherwise.
I want the IIf statement to check 'VP OtherGlue on valve/hinge' if
'VPOther:ExtraIncreased Resistance' is checked.

I used the following IIf statement:
VP OtherGlue on valve/hinge: IIf([VP Other:Extra Increased
Resistance]=True,True)
When I do this, I get a -1 instead of a checked check box. How do I change
my statement so that my check box is checked?

I'd suggest using a Form (tables and query datasheets have no usable events)
with an checkbox bound to each field; put code in the 'VPOther:ExtraIncreased
Resistance' checkbox's AfterUpdate event like:

Private Sub VPOther_ExtraIncreased_Resistance_AfterUpdate()
Me![VP OtherGlue on valve/hinge] = Me![([VP Other:Extra Increased Resistance]
End Sub

This will match the value of the second checkbox to the first (i.e. check it
if the user checks it, uncheck it when it's unchecked).
 
R

Radhika

I am not very familiar with update queries. Where do I insert the following
expression:
"Update tblYourTable Set YourFirstField = True Where
YourSecondField = True"

Thank you for your help!

Beetle said:
The IIf statement is only going to return a value, not change the value
of any existing records.

If you need to change the value of existing records, you would typically
run an update query, something like;

"Update tblYourTable Set YourFirstField = True Where
YourSecondField = True"
--
_________

Sean Bailey


Radhika said:
I am trying to create a query that uses two fileds ('VP OtherGlue on
valve/hinge', 'VROther:Extra Increased Resistance') from the same table
'tbl_TEPRecords'.
Both field are check boxes.
I want the IIf statement to check 'VP OtherGlue on valve/hinge' if
'VPOther:ExtraIncreased Resistance' is checked.

I used the following IIf statement:
VP OtherGlue on valve/hinge: IIf([VP Other:Extra Increased
Resistance]=True,True)
When I do this, I get a -1 instead of a checked check box. How do I change
my statement so that my check box is checked?

Thankyou,
Radhika
 
J

John W. Vinson

I am not very familiar with update queries. Where do I insert the following
expression:
"Update tblYourTable Set YourFirstField = True Where
YourSecondField = True"

In the SQL window of a new Query (View... SQL on the menu). Change the table
and fieldnames to those in your table of course.

Or, create a new query based on the table; use the Query menu option to change
it to an Update query; put True as a criterion on the field
[VP Other:Extra Increased Resistance] and also on the "Update To" line under
[VP OtherGlue on valve/hinge].

Do note that Access can have problems with fieldnames containing punctuation
such as colons and slashes. You might want to consider using more
computer-friendly names (only numbers and letters, no blanks, no punctuation
other than underscores), and use labels on forms or reports to display
human-friendly names.
 

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

Similar Threads

IIf statement in update query 3
Update query with true/false 3
Date query 4
iif statement 2
Complicated IIf Statement Problem 24
Too many IIF statements 3
iif statement 5
I damn thee IIF statement..... 6

Top