Message Box Code Help

G

Guest

I have a message box coded on a before update event. I need to know how to
change this code so if the users response is no the record/input will be
removed so the user can return to the switchboard to look up the order number
in another form. The ordernumber is a required field so it will not allow
the user to backout without inputting something at this point.

Here is the current code.

Private Sub ordernumber_BeforeUpdate(Cancel As Integer)
If DLookup("ordernumber", "qry ordernumbers", "ordernumber=" &
ordernumber.Value) Then
Cancel = (MsgBox("Duplicate Order, Do you want to Proceed?", vbQuestion +
vbYesNo)) = vbNo
If Cancel = 0 Then
Me!duplicate = True

End If
End If
End Sub

Please HELP!
Barry
 
G

Guest

Hi BDPIII,

The 'cancel as integer' part of the beforeUpdate event allows you to cancel
the update if it is not required, set to -1 to cancel, or 0 to allow the
update to happen. Your message box should be a separately dimmed integer;

Private Sub ordernumber_BeforeUpdate(Cancel As Integer)
dim intmsg as Integer

If DLookup("ordernumber", "qry ordernumbers", "ordernumber=" &
ordernumber.Value) Then
intmsg = (MsgBox("Duplicate Order, Do you want to Proceed?", vbQuestion +
vbYesNo))
If intmsg = vbYes Then
Me!duplicate = True
Else: cancel = -1
End If
End If
End Sub

If you want to undo any changes then you can use;

If Me.Dirty Then
Me.Undo
End If

hope that helps,

TonyT..

End If
End If
End Sub
 
G

Guest

Tony,

Thanks for the input I figured out the Dim intresponse sequence from another
post, But I was still stuck on the undo part which you just gave me!

Thank you BIG help!

Barry
 

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