Office Watch

Office 2013

Office Mobile / iPad

Office 2010

Office 2007

Office 2003

Office XP

Office for Mere Mortals



Buying Office

Office 365


Office News Wire

Join us!

Our Ebooks

Mobile | PDA



Command Finder

Microsoft Office Bookshop



Preventing duplicate data entry

How to prevent duplicate data entry in different records.

View this page on the new web site - click here

by Access Watch

Bookmark and Share

  | Mobile | click for more article services     

View this page on the new web site - click here

Q:  Nigel Heremaia wants to prevent users from entering the same data in the FirstName and LastName fields in different records.  He is using this code, but it isn't working:

Private Sub Form_BeforeUpdate(Cancel As Integer)


Dim FirstName

Dim LastName

Dim FullName


FirstName = DLookup("[FirstName]", "tblClients", "[FirstName] ='" _

   & Me!FirstName & "'")

LastName = DLookup("[LastName]", "tblClients", "[LastName] ='" _

   & Me!LastName & "'")

FullName = FirstName & LastName

    If FullName <> 0 Then

        MsgBox "Client has already been entered in the database."

        Cancel = True

    End If

End Sub


A:  The problem here is that you are comparing FullName to 0, and the expression FullName <> 0 will always evaluate to True, because whatever value is in the FullName variable, it is a String value, not a numeric value.  To clarify this, declare your variables as String, and wrap the FirstName and LastName variables with Nz() – this converts Nulls in text fields to zero-length strings.  Then you can check whether Full Name <> "" (instead of 0).  That should work the way you intend.

Article posted: Tuesday, 27 May 2008

View this page on the new web site - click here

there's more ...

If you liked this article you'll LOVE our new ebooks.

Office 2013: the real startup guide

OFFICE 2013: the real startup guide Everything you need to know about Office 2013 but Microsoft won't tell you.

How to save money, install, configure and use the new features in Office 2013.  Get it today - click here.

Windows 8 for Microsoft Office users

Windows 8 for Microsoft Office users A practical guide the new, changed and unfamiliar in Windows 8

A focused and unvarnished look at Windows 8, especially written for the many people who use Microsoft Office  Get it today - click here.

ORGANIZING OUTLOOK EMAIL - tame your Outlook 2010 Inbox

100+ pages of practical tips and help to streamline, automate and search your Inbox.  Get more than you ever thought possible from Outlook.  Read it today - click here.

Article Services sponsored by: Office Watch Ebooks - available now to download and read today.
RSS feed for this category Subscribe

Translate | Mobile | Links
 Add to: Bookmarks | | DiggThis | Yahoo! My Web

New & Popular
» New web site
» Two ways for sorting by Number
» Office for iPad, September updates
» Why is Gene Cernan ignored in Word?
» DropBox prices drop but is it enough?
» Sort by hidden column in Word

Office Watch, Office for Mere Mortals, Access Watch and all titles used within the publications are Copyright © 1996-2014 Office Watch.
Microsoft Office, Microsoft Word, Microsoft Excel, Microsoft Outlook, Microsoft Powerpoint and doubtless many other names are registered trademarks of Microsoft Corporation.

Search  |  Sitemap |  Popular Topics | Privacy Statement |  Advertising |  Twitter |  Feedback / Contact Us
Office Watch is definitely not affiliated with Microsoft - and that's just one reason why we are so useful to Microsoft Office users around the world J (Erko).