Hi,
I have been trying to adapt this code for my database. I'm using MS Access 2007, and most front end users are in 2010.
The name of the underlying table is tblStudents, and the record source is qryMainDataEntr y (which links two tables).
The Form is called frmMainDataEntr y. The name of the field holding the data is called StudentName and it has the same name in the table and the form (I know it probably shouldn't).
The code I have tried to apply in the Form is this:
I suspect the code is confused between the tables and forms, and have tried to differentiate them with tblStudents_Stu dentName and frmMainDataEntr y_StudentName - but that isn't doing the trick.
The code in this thread seems to apply to data entry in the table, and maybe that is part of the issue?
I would like this code to just return a message that the student's name already exists in the database as soon as the user moves out of that field, not when the whole form has been completed. I need to allow duplicates.
Thank you in anticipation of your help. I hope I have provided enough clear information.
regards,
Marc
(Original hijacked thread - Want Access to notify me if a record already exists.)
I have been trying to adapt this code for my database. I'm using MS Access 2007, and most front end users are in 2010.
The name of the underlying table is tblStudents, and the record source is qryMainDataEntr y (which links two tables).
The Form is called frmMainDataEntr y. The name of the field holding the data is called StudentName and it has the same name in the table and the form (I know it probably shouldn't).
The code I have tried to apply in the Form is this:
Code:
Private Sub StudentName_BeforeUpdate(Cancel As Integer)
If DCount("StudentName]", "tblStudents", "[StudentName]= '" & Me![StudentName] & "'") > 0 Then
MsgBox "Name Is Already In Database!"
End If
End Sub
I suspect the code is confused between the tables and forms, and have tried to differentiate them with tblStudents_Stu dentName and frmMainDataEntr y_StudentName - but that isn't doing the trick.
The code in this thread seems to apply to data entry in the table, and maybe that is part of the issue?
I would like this code to just return a message that the student's name already exists in the database as soon as the user moves out of that field, not when the whole form has been completed. I need to allow duplicates.
Thank you in anticipation of your help. I hope I have provided enough clear information.
regards,
Marc
(Original hijacked thread - Want Access to notify me if a record already exists.)
Comment