Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / September 2005

Tip: Looking for answers? Try searching our database.

how do i check for duplicate entry in a table from a form text box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
greg higgy - 29 Sep 2005 05:54 GMT
I have a table named 'invoices' with a field named 'invoice#'. I am creating
a form which a person fills out different fields. The form is named
'FInvoices'. One text box is named 'Invoicebox'. What I am needing to do is
when a number is entered, and when the focus to that text box is lost, it
checks the 'invoices' table for a duplicate number (in the Invoice# field),
if there is, an error message will pop up, allowing the cashier to correct
the error. This checking needs to be done before the cashier is allowed to
continue.  

This is my first real project I am attempting and my skill level would be
about "Intermediate". I have looked at several "dlookup" examples but could
not get any of them to work in my example.

Any help would be great. Thanks in advance.

greg
ozgirl - 29 Sep 2005 08:13 GMT
Hi Greg,

this may help

place it on the before update event on your invoice number field on your form

Dim InvID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

InvID = Me.InvoiceNumber.Value
stLinkCriteria = "[txtInvoiceNumber]=" & "'" & InvID & "'"

   'Check Details table for duplicate Invoic Number

   If DCount("InvoiceNumber", "your table name", stLinkCriteria) > 0 Then
       'Undo duplicate entry
       'Me.Undo

       'Message box warning of duplication

       MsgBox "Warning Invoice Number " _
       & InvID & " has already been entered.", vbInformation , "Duplicate
Information"
               
   End If

Set rsc = Nothing

regards

Lee-Anne

>I have a table named 'invoices' with a field named 'invoice#'. I am creating
>a form which a person fills out different fields. The form is named
[quoted text clipped - 12 lines]
>
>greg
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.