Check Box IIF Statement (1 Viewer)

cktcPeterson

Member
Local time
Today, 13:26
Joined
Mar 23, 2022
Messages
73
I have a check box (cbxPC)

I want an iff statement

when true, then

[PremierCourseCredit]=[Award Amount]

if false then [PremierCourseCredit]=0

Not sure how to write it or where to put the code.

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:26
Joined
Sep 21, 2011
Messages
14,310
I would use a standard If statement?
I would also use the AfterUpdate event.
 

cktcPeterson

Member
Local time
Today, 13:26
Joined
Mar 23, 2022
Messages
73
so

=IIF([cbxPC],[PremierCourseCredit]=[Award Amount], "0")

The code turns red.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:26
Joined
Sep 21, 2011
Messages
14,310
No. I said a standard IF statement. :(
Code:
If Me.cbxPC Then
    Me.PremierCourseCredit = Me.AwardAmount ' get rid of spaces in field/Control names
Else
    Me.PremierCourseCredit = 0
End If

You are trying to use an expession which *might* work in PremierCourseCredit control, but not with that syntax.
 

cktcPeterson

Member
Local time
Today, 13:26
Joined
Mar 23, 2022
Messages
73
Thank you for this. Is it okay to have an _?
I updated the field to Award_Amount

However the code is not working.
 

LarryE

Active member
Local time
Today, 14:26
Joined
Aug 18, 2021
Messages
592
I have a check box (cbxPC)

I want an iff statement

when true, then

[PremierCourseCredit]=[Award Amount]

if false then [PremierCourseCredit]=0

Not sure how to write it or where to put the code.

Thanks
Code:
If Me.cbxPC = True Then
    Me.PremierCourseCredit = Me.AwardAmount
Else
    Me.PremierCourseCredit = 0
End If
Put the code in the OnClick event of the cbxPC checkbox control
 

cktcPeterson

Member
Local time
Today, 13:26
Joined
Mar 23, 2022
Messages
73
Got it to work.
Had to add me.refresh at the end.

Thanks for all your help!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:26
Joined
Feb 19, 2002
Messages
43,283
Me.Refresh has the unintended consequence of forcing Access to save the current record. Make sure you don't force the record to be saved before all the data is entered or you will be causing validation errors regarding missing/incorrect data because you are forcing the record to be saved before the user has finished with the data entry.
 

Users who are viewing this thread

Top Bottom