A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Display a message box "this entry is a duplicate"



 
 
Thread Tools Display Modes
  #1  
Old June 3rd, 2010, 06:32 PM posted to microsoft.public.access
Tina
external usenet poster
 
Posts: 350
Default 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.
  #2  
Old June 3rd, 2010, 07:07 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Display a message box "this entry is a duplicate"

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" wrote in message
...
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.



  #3  
Old June 3rd, 2010, 07:16 PM posted to microsoft.public.access
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Display a message box "this entry is a duplicate"

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" wrote in message
...
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.



  #4  
Old June 3rd, 2010, 07:18 PM posted to microsoft.public.access
Jörn Bosse[_3_]
external usenet poster
 
Posts: 20
Default Display a message box "this entry is a duplicate"

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:17 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.