Getting error, do I need error capturing code?

L

Lorraine

I am wanting to check if the CompDate field is null or not. If it has a date
then I want the txtPlannedAct field to be checked for the "Stand Exam" value.
If both exist then the Water_Quality checkbox should auto fill. If a
CompDate is entered then the chkCompleted checkbox should auto fill. If the
CompDate field is empty then both checkboxes should be unchecked.

This is all working fine. But I also want the focus to go to the
txtComments field and the txtComments field to auto fill with "water quality
ok" if a CompDate is entered and the txtPlannedAct field value is "Stand
Exam."

After the txtComments field auto fills with "water quality ok" I get a
run-time error 2115 "The macro or function set to the BeforeUpdate or
ValidationRule property for this field is preventing Microsoft Access from
saving the data in the field" and yet the data does save. Do I just need to
add some error capturing to my code? If so, how? I'm not too familiar with
error capturing code.

Private Sub txtCompDate_AfterUpdate()

If Me.CompDate.Value <> IsNull(CompDate.Value) Then
If Me.txtPlannedAct.Value = "Stand Exam" Then
Me.Water_Quality.Value = -1
End If
Me.chkCompleted.Value = -1
Me.txtComments.SetFocus
Me.txtComments.Text = "water quality ok" 'GET A RUN TIME ERROR HERE!
Else
Me.chkCompleted.Value = 0
Me.Water_Quality.Value = 0
Me.Inactive.SetFocus
End If

End Sub
 
F

freakazeud

Hi,
try

Private Sub txtCompDate_AfterUpdate()

If Not IsNull(CompDate) AND Me.txtPlannedAct = "Stand Exam" Then
Me.Water_Quality = True
Me.chkCompleted = True
Me.txtComments = "water quality ok"
Else
Me.chkCompleted = False
Me.Water_Quality = False
Me.Inactive.SetFocus
End If

End Sub

HTH
Good luck
 
D

Dennis

You should also check each column definition in your table. Are there any
that say "allow null value" = NO ? If so, and a value you're trying to save
is null, you'll get an error.
 

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