VBA code for without entry Duplicate records (1 Viewer)

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
Hello,

How to give a VBA code for duplicate records is without entry in Subform datasheet. I just used in the screenshot code but that is not working properly. I have attached the screenshot with explanation so can anyone help how to change a vba code for without entry duplicate names. :confused:


Thank,
Sandhya.
 

Attachments

  • Screenshot 22.10.2014.jpg
    Screenshot 22.10.2014.jpg
    51.2 KB · Views: 84

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:33
Joined
Aug 30, 2003
Messages
36,128
Try the before update event. The enter event occurs when focus enters the textbox, not when you hit enter.
 

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
Thanks for reply,
Yes, i just tried on Before Event but not working. cursor is moving normally without shown any msg. :( i think that code is correct?

Sandhya.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:33
Joined
Aug 30, 2003
Messages
36,128
You wouldn't get the message until you tried to update the field (tab or enter out of the textbox). Also, don't use the .Text property.
 

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
Yes, am also tried below code without .Text property but not working. :banghead:

Private Sub clubb_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler

If DCount("clubb", "Table1", "clubb = '" & Me.clubb & "'") > 0 Then
Beep
MsgBox "Don't allow negative values", vbOKOnly, "Required Data"
Cancel = True
Me.nnumber.SetFocus
Exit Sub
End If

ErrorHandler:
End Sub

i have attached db can you please see once my db.


Thanks,
Sandhya.
 

Attachments

  • M22.zip
    154.7 KB · Views: 83

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:33
Joined
Aug 30, 2003
Messages
36,128
That field is a calculated field, so you aren't entering data in it. The before update event doesn't run for calculated fields. Your code would have to be in one or both of the other controls.
 

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
I need to allow duplicate records in other fields of NName, number because same names is allow with different numbers if like James 555 is already exist so will give a same name with different number like James 666 or James 1212 or James 1313 so both fields are need to allow duplicate names and numbers otherwise final in clubb filed is not allowed the same repeated name in the field. So how to use VBA code in this case? :banghead: :banghead:

--
Sandhya.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:33
Joined
Aug 30, 2003
Messages
36,128
You test both of those fields together.
 

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
how can i test both of those fields together? you mean field by field or both fields at a time? i think on both fields are not possible to give a code at a time?? is it possible :confused:
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:33
Joined
Aug 30, 2003
Messages
36,128
By testing both I mean:

If DCount("*", "Table1", "NName = '" & Me.NName & "' And nnumber = '" & Me.nnumber & "'") > 0 Then
 

Lal-Bangalore

New member
Local time
Today, 15:03
Joined
Oct 23, 2014
Messages
4
Hello friends I am a beginner in ms access 2010. I need some help. I have a main table called Mailing_Entry_Table in this table I have the following fields: SlNo.(Primery_Key), Dep_Id, M-Date, Cmbo_M-title, Sign, M-Desi, M-Dept, M-Name, Institute, Address1, Address2, City, Pin, Phone. where Cmbo_m_title is a combo box, and the field name is acquired form a different table called Title_Table. Institute is also a combo, where the records are drawn from another table called fulllist (This contains the details of various Institutions, address, Pin and Phone)
I have a form called Maling_Lable_Entry_Form, in this form the date, name, designation department are entered Other fields like initiation name address1, address2, city, pin and the title is drawn from different tables as stated above.
Now, the help I am looking for is: when I enter a data. And press save! Access should check for duplicate entry, if the same name with the title and institution same has already been entered????? If yes give me an option to either save and continue and go the next entry without saving this entry.
How to check this duplicate entry……..
Regards,
Lal
 

sandya

Registered User.
Local time
Today, 15:03
Joined
Oct 27, 2013
Messages
82
Brand, Model & Item fields are text fields and Items Description is calculated filed ([Brand] & " " & [Model] & " " & [Item]). So in Brand, Model & Item fields is need to allow duplicate records because same Brand is repeated with different models & different Items and same Model is repeated with different brands. And sometimes user using only Brand without Model & Item both of is blank as per above shown screenshot. And sometimes using only Model or Item as per above screenshot. So user however using the above fields then finally doesn’t repeat duplicate records in the Item Description. Above ID: 57 & 69 1st row and last row item details are same so don’t allow this type of duplicate records in the Item Description. If user force to entering the duplicate record then will show a message (Already Exist) and cancel it. In this case how to use the VBA code on Brand, Model & Item fields?? i think if using VBA code on Brand, Model, Item fields then don’t allow the duplicate records in this fields. I think possible only on Items Description?

Attached the Screenshot with Explanation


Sandhya.
 

Attachments

  • ScreenshotFinal1.jpg
    ScreenshotFinal1.jpg
    98.9 KB · Views: 79

Users who are viewing this thread

Top Bottom