423,873 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,873 IT Pros & Developers. It's quick & easy.

How to check duplicate records

P: 17
Hello,

I need help.

I have a form and I would like to do a check when I enter a data into the field and once I press enter into the field it will check whether is duplicate or not.

currently I have a form with a subform and when I enter the data into the field it does not give me an error till I goto the subform, which is not good.

Please advise how to fix this.

Many Many thanks
Jul 7 '07 #1
Share this Question
Share on Google+
3 Replies


dima69
Expert 100+
P: 181
Hello,

I need help.

I have a form and I would like to do a check when I enter a data into the field and once I press enter into the field it will check whether is duplicate or not.

currently I have a form with a subform and when I enter the data into the field it does not give me an error till I goto the subform, which is not good.

Please advise how to fix this.

Many Many thanks
Try this (substitue your names). DAO reference required.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtNewData_BeforeUpdate(Cancel As Integer)
  2. Dim rs As Recordset
  3. Set rs = CurrentDb.OpenRecordset("MyDataTable", dbOpenSnapshot)
  4. rs.FindFirst "txtDataField = """ & Me![txtNewData] & """"
  5. If Not rs.NoMatch Then
  6.     Cancel = True
  7.     MsgBox "Duplicate Value"
  8. End If
  9. End Sub
Jul 7 '07 #2

P: 17
Try this (substitue your names). DAO reference required.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtNewData_BeforeUpdate(Cancel As Integer)
  2. Dim rs As Recordset
  3. Set rs = CurrentDb.OpenRecordset("MyDataTable", dbOpenSnapshot)
  4. rs.FindFirst "txtDataField = """ & Me![txtNewData] & """"
  5. If Not rs.NoMatch Then
  6.     Cancel = True
  7.     MsgBox "Duplicate Value"
  8. End If
  9. End Sub
Thank you it works perfectly
Jul 8 '07 #3

P: 1
Thank you very much, it works for me also!
Jul 16 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.