From: Tina on
How can I display a message box on a form if the shipment number is a
duplicate? I need a message box to pop up when user attempts to tab out of
the field.

Thank you.
From: Douglas J. Steele on
Something like:

Private Sub txtShipNum_BeforeUpdate(Cancel As Integer)

If DCount("*", "MyTable", "ShipNum = '" & Me.txtShipNum & "'") > 0 Then
Msgbox Me.txtShipNum & " already exists."
Cancel = True
End If

End Sub

This assumes that your text box is named txtShipNum, that the name of the
field in table MyTable is ShipNum and that it's a text field.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Tina" <Tina(a)discussions.microsoft.com> wrote in message
news:F74F319A-B9CC-4E2D-8980-02825A285035(a)microsoft.com...
> How can I display a message box on a form if the shipment number is a
> duplicate? I need a message box to pop up when user attempts to tab out
> of
> the field.
>
> Thank you.


From: Jeff Boyce on
Tina

Would you rather have a way to "find" an existing number if one existed, or
have your computer tell you that you can't use the number you just tried to
use?

It might be a bit more user friendly to provide a combobox (drop-down)
containing existing [ShipmentNumber]s, set the LimitToList property to Yes,
and add a NotInList event to allow the user to create a new
[ShipmentNumber]. More work for you, (much) less for the user...

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Tina" <Tina(a)discussions.microsoft.com> wrote in message
news:F74F319A-B9CC-4E2D-8980-02825A285035(a)microsoft.com...
> How can I display a message box on a form if the shipment number is a
> duplicate? I need a message box to pop up when user attempts to tab out
> of
> the field.
>
> Thank you.


From: Jörn Bosse on
Am 03.06.2010 19:32, schrieb Tina:
> How can I display a message box on a form if the shipment number is a
> duplicate? I need a message box to pop up when user attempts to tab out of
> the field.
>
> Thank you.

Hello,

try something like this in when the control is about to lose it´s focus.

Dim intZ as Integer

intZ = DCount("FieldinTable","Tablename","shipmentnumber = " &
Me.Yournewnumber)
If intZ >= 1 Then
Me.Yournewnumber.Undo
MsgBox "number already exists"

shipmentnumber is the name of the column in your table with the numbers
you want to check. This will work if your shipment number is an integer.
Me.Yurnewnumber is the name of your textfield in the form.

Regards
Jörn