Updating Yes/No Checkbox based on Another Fields Data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm new to Access so please give full info - don't leave to my imagination.

I have a database with a numeric field named 'Hours' and a yes/no checkbox
field named 'Form_Attached'.

I would like to update the yes/no checkbox field based on the content of the
'hours' field. If the 'hours' field is >0, then I want the yes/no box to be
checked and if the 'hours' field is empty, then I want the yes/no box NOT to
be checked.

How can I make that happen?
 
You don't. That would be redundant. If an entry greater than 0 always
indicates a true state, then there is no reason to maintain that data in two
fields.

In your forms and reports, you can certainly include a separate checkbox and
have it display based on the value in your "hours" field, but you don't need
to store the data in a table.
 
Look at the Properties associated with the Hours textbox. Find the
AfterUpdate event, put [Event Procedure] in the box beside it, then click on
the ellipsis (...) to the right. You'll be taken into the VB Editor, with
something like the following prefilled for you:

Private Sub Hours_AfterUpdate()

End Sub

Put the following code between those two lines:

Me.Form_Attached = (Me.Hours > 0)

so that you end up with:

Private Sub Hours_AfterUpdate()

Me.Form_Attached = (Me.Hours > 0)

End Sub

That's it. You're done.
 
Back
Top