How to cancel?

H

hanski

Hi

In my form I input a value and AfterUpdate checks the value and looks
that the value is wrong. How can I cancel this input automatically,
because my table does not accept null-value into that field, what I am
trying to input?

Hanski
 
J

John W. Vinson

Hi

In my form I input a value and AfterUpdate checks the value and looks
that the value is wrong. How can I cancel this input automatically,
because my table does not accept null-value into that field, what I am
trying to input?

Hanski

You can't, in the AfterUpdate event - it's too late, since it fires AFTER the
update has already been done. Use the BeforeUpdate event instead, and set its
Cancel argument to True to cancel the update.

John W. Vinson [MVP]
 
H

hanski

You can't, in the AfterUpdate event - it's too late, since it fires AFTER the
update has already been done. Use the BeforeUpdate event instead, and set its
Cancel argument to True to cancel the update.

John W. Vinson [MVP]

Hi.

My code is:

Private Sub datethis_BeforeUpdate(Cancel As Integer)
If Me.code = "-Select-" Then
MsgBox ("Select first the code!!")
DoCmd.CancelEvent
Cancel = True
End If
End Sub

It gives me the msgbox text but it does not allow me to goto to the
code-box to change the code! It will never let me go out of the
datethis box, because in the code box is text -Select-.

What I am trying to do is this:
If the code is not selected and you try to input a date, it would tell
me that the code is not selected and it would go to the code-box and
it would empty the datethis box.

Hope you understand....

hanski
 
G

Guest

You misunderstood what John said. Your code should look like this:

Private Sub datethis_BeforeUpdate(Cancel As Integer)
With Me
If .code = "-Select-" Then
MsgBox ("Select first the code!!")
.datethis = Null
.code.Setfocus
Cancel = True
End If
End With
End Sub
 

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