talbright
talbright

Reputation: 446

ms access - checkbox based on value of textbox

I am building a report in access 2007, and trying to set a checkbox to true based on the value of a string in a textbox. For example: If txtBoxValue = "Injury" then chkBoxValue = True(Checked) Else chkBoxValue = False(unchecked).

This is the value I have in the source control of chkBoxValue.

=IIf([txtBoxValue]=”Injury”,1,0)

I am new to VBA, and any help would be appreciated.

Upvotes: 2

Views: 6147

Answers (2)

HansUp
HansUp

Reputation: 97131

This should work as the control source of chkBoxValue:

=([txtBoxValue]="Injury")

Be careful about the quotes you use in VBA code. Notice you used ” (ASCII 148) and I used " (ASCII 34).

Edit: As @nicholas pointed out, that control source expression will give you Null when [txtBoxValue] is Null. If you prefer False instead, add the Nz() function.

=(Nz([txtBoxValue],"")="Injury")

Upvotes: 5

nicholas
nicholas

Reputation: 3047

True / False fields use values -1 and 0 in Access. You also have constants TRUE and FALSE.

The control source of the checkbox should read:

=IIf([txtBoxValue]="Injury",TRUE,FALSE)

Upvotes: 0

Related Questions