Validate Form Data before allowing field to change

  • Thread starter naigy via AccessMonster.com
  • Start date
N

naigy via AccessMonster.com

Hi All,

I have a form which is used for monitoring repairs.

On this form the key bits of information are
Service Date (TextBox)

Linked Subform using service date, serial number and technician (all on main
form and hidden on the subform)

Inspected (Checkbox)
Repaired (Checkbox)
Checked (Checkbox)

What I want to do is stop the service date field being changed if any of
these checkboxes in the subform are ticked. I had this working previously I
think where when I clicked out of the field it would prompt to advise linked
data is logged and the service date field would revert back to what it was
with the undo function.

I have the code working in the service date got focus event (but no undo
function) but I would prefer it to only prompt when the field is changed
(because sometimes we select the service date field and use the sort or
filter options and I would prefer to not be prompted when we are doing this.
It is just I have been unable to find the right event I think.
 
T

tina

try the *control's* BeforeUpdate event; it should only fire when the data is
changed via data entry (not when data is changed programmatically - by
setting the value, running an update query, etc.)

hth
 
A

Arvin Meyer [MVP]

The value of a check in a checkbox is -1. The value if false is 0, so in the
After update event of each of the 3 checkboxes a piece of code like this
(untested) should do the trick:

Private Sub Inspected_AfterUpdate()
If [Inspected]+[Repaired]+[Checked] < 0 Then
Me.DateField.Locked = True
Else
Me.DateField.Locked = False
End If
End Sub

You'll also need to add it to the Form's Current event, so as the record
changes, the field will be appropriately locked or unlocked.
 

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

Top