Display a message box "this entry is a duplicate"

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.
0
Utf
6/3/2010 5:32:25 PM
access 16762 articles. 2 followers. Follow

3 Replies
1557 Views

Similar Articles

[PageSpeed] 13

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@discussions.microsoft.com> wrote in message 
news:F74F319A-B9CC-4E2D-8980-02825A285035@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. 


0
Douglas
6/3/2010 6:07:31 PM
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@discussions.microsoft.com> wrote in message 
news:F74F319A-B9CC-4E2D-8980-02825A285035@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. 


0
Jeff
6/3/2010 6:16:03 PM
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
0
UTF
6/3/2010 6:18:58 PM
Reply:

Similar Artilces:

Display a message box "this entry is a duplicate"
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. 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...