Msgbox response action

G

Guest

I have a msg box that pops up on the before update tag on a forms textbox,
when a duplicate order number is input into a form. I need the response to
of the msgbox to trigger 1 of two things depending on the users answer.

Answer Yes: Update a duplicate yes/no field on the form with a check box
(txt box name duplicate)
Answer No: Delete the users entry into the text box or the record and allow
them to escape the form. The field is a field required in the record so it
will not allow you to backout of the form!

Here is the code I have in place for the msg box

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 Response = vbYes Then
Me![duplicate] = -1
Else
Mystring = "No"



End If
End If
End If
End Sub

It is not updating the duplicate field on a yes response but no error is
received. I do not have any idea of the code that may delete the entry in
the form.

Any help would be greatly appreciated!

Barry
 
J

Jeff L

Response needs to get the value of the message box asking whether or
not to procede, not Cancel. You should probably declare response as a
variable.
Dim Response as Integer

Hope that helps!
 
G

Guest

Thanks Jeff I will try to use that and report back, would have helped if I
had posted the correct code I had in at the time, Had a bit of extra code on
the end.

Jeff L said:
Response needs to get the value of the message box asking whether or
not to procede, not Cancel. You should probably declare response as a
variable.
Dim Response as Integer

Hope that helps!


BDP said:
I have a msg box that pops up on the before update tag on a forms textbox,
when a duplicate order number is input into a form. I need the response to
of the msgbox to trigger 1 of two things depending on the users answer.

Answer Yes: Update a duplicate yes/no field on the form with a check box
(txt box name duplicate)
Answer No: Delete the users entry into the text box or the record and allow
them to escape the form. The field is a field required in the record so it
will not allow you to backout of the form!

Here is the code I have in place for the msg box

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 Response = vbYes Then
Me![duplicate] = -1
Else
Mystring = "No"



End If
End If
End If
End Sub

It is not updating the duplicate field on a yes response but no error is
received. I do not have any idea of the code that may delete the entry in
the form.

Any help would be greatly appreciated!

Barry
 
G

Guest

OK I accomplished the check box for the deuplicate field by using the code
below.

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

End If
End If
End Sub

Any idea on how to delete or remove the entry if No is chosen would be a big
help.

Barry
 
G

Guest

Ignor last post as that is not working properly here is my current code,
still at square 1.

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
Else
Response = vbYes

End If
End Sub
 
J

Jeff L

An issue that I'm seeing is that your DLookup statement will never
evaluate to a true statement. It will only evaluate to a number.
Also, you will probably get errors when the DLookup returns a null
value ie does not find a match. This would work:

If Not ISNull(DLookup("ordernumber", "qry ordernumbers", "ordernumber="
&
ordernumber.Value)) Then 'OrderNumber Exists

Hope that helps!
 

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