Checking For Duplicate Entries using VBA 
Author Message
 Checking For Duplicate Entries using VBA

I have a form called "frmRecharges" based on a table called
"tblRecharges" which has the Primary key field called "Order Number"

Is there a way for a Msgbox to be displayed, say after the lost focus
event, on the Order number field if a new order number is the same as an
existing order number already in the table i.e. a duplicate number

MAny thanks
Chris



Sun, 12 Mar 2000 03:00:00 GMT  
 Checking For Duplicate Entries using VBA

Chris:

If the Order Number field is actually set as the Primary Key in table
tblRecharges, then Access itself produce an error on an attempted duplicate
entry. Here is a module that will check for the duplicate error and produce
the message you want. Actuate the module with the form Before Update
Property or a Write Record Macro. This module uses a Write-Record
Pushbutton.

        -- Wesley

Sub Write_Record () 'ACTION FOR "WRITE_RECORD" PUSHBUTTON

        'IF KEY IS NOT UNIQUE GOTO ERROR ROUTINE
    On Error GoTo Err_Write_Record

        'KEY IS UNIQUE, SAVE RECORD.
    DoCmd DoMenuItem A_FormBar, A_File, A_SaveRecord
    DoCmd GoToControl "Name"

Exit_Write_Record:
Exit Sub

Err_Write_Record:
        'STOP SAVE RECORD ACTION, DISPLAY MESSAGE, GOTO [FIRST NAME].
    DoCmd CancelEvent
    MsgBox "Duplicate Record! Reenter or Cancel.", , "M I D A S   R E C O R
D"
    DoCmd GoToControl "First Name"
    Resume Exit_Write_Record
End Sub



Quote:
> I have a form called "frmRecharges" based on a table called
> "tblRecharges" which has the Primary key field called "Order Number"

> Is there a way for a Msgbox to be displayed, say after the lost focus
> event, on the Order number field if a new order number is the same as an
> existing order number already in the table i.e. a duplicate number

> MAny thanks
> Chris



Sun, 12 Mar 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Real-time checking of duplicate entries

2. before saving a record, check duplicate entries

3. Duplicate entries when coping items with VBA macro

4. Duplicate entries when coping items with VBA macro

5. checking for invalid entry using dropdown style Combo

6. Code to duplicate a table structure using VBA

7. Using VBA to delete autotext entries

8. An easy solution here (VBA code) to delete duplicate entries (email, calendar or task entries) in Outlook

9. Detecting Duplicate Entries On Direct Input

10. Deleting duplicate entry in subform

11. validartion code for duplicate entries

12. Duplicate contact Entries

 

 
Powered by phpBB® Forum Software