Before Update and cancelling the write to table

B

Brad

Thanks for taking the time to read my question.

I have a set of criteria that if met during the Before
Update event of a form, should tell the user that the
record could not be written because it would create a
duplicate record.

I can do that part, but how do I stop Access from writing
to the table? Some sort of cancel event or something?

I already have a key on the table that includes the date
on the form, as well as a few prices, also on the form.
If any one of these are changed the record can be
written, if all fields but the date are changed, the key
will allow the record to be written, but the date has to
change, and there inlies my problem. If the user changes
only one price but not the date, it will create two
prices on the same day, and I don't want that to happen.

Thanks again for your help,

Brad

What I have so far...

---------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Exists As Boolean

Exists = DLookup
("PricingIngredTextCode", "qryCheckIfCurrentIngredEffectiv
eDateAlreadyExists")

If Exists = True Then
Cancel 'I need something here to stop Access from
writing to the source table.
End If
End Sub
 
F

fredg

Thanks for taking the time to read my question.

I have a set of criteria that if met during the Before
Update event of a form, should tell the user that the
record could not be written because it would create a
duplicate record.

I can do that part, but how do I stop Access from writing
to the table? Some sort of cancel event or something?

I already have a key on the table that includes the date
on the form, as well as a few prices, also on the form.
If any one of these are changed the record can be
written, if all fields but the date are changed, the key
will allow the record to be written, but the date has to
change, and there inlies my problem. If the user changes
only one price but not the date, it will create two
prices on the same day, and I don't want that to happen.

Thanks again for your help,

Brad

What I have so far...

---------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Exists As Boolean

Exists = DLookup
("PricingIngredTextCode", "qryCheckIfCurrentIngredEffectiv
eDateAlreadyExists")

If Exists = True Then
Cancel 'I need something here to stop Access from
writing to the source table.
End If
End Sub

The DLookUp is returning a value of True or False?

If Exists = True Then
Cancel = True
End If
 
M

Marshall Barton

Brad said:
I have a set of criteria that if met during the Before
Update event of a form, should tell the user that the
record could not be written because it would create a
duplicate record.

I can do that part, but how do I stop Access from writing
to the table? Some sort of cancel event or something?

I already have a key on the table that includes the date
on the form, as well as a few prices, also on the form.
If any one of these are changed the record can be
written, if all fields but the date are changed, the key
will allow the record to be written, but the date has to
change, and there inlies my problem. If the user changes
only one price but not the date, it will create two
prices on the same day, and I don't want that to happen.

Thanks again for your help,

Brad

What I have so far...

---------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Exists As Boolean

Exists = DLookup
("PricingIngredTextCode", "qryCheckIfCurrentIngredEffectiv
eDateAlreadyExists")

If Exists = True Then


All you need is:

Cancel = True
 

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