Hi all,
Thanks for taking the time to read this. I am quite new to Access, and i was wondering whether you could help me with something?
I work at a School and have been given the task to devise a detention sheet.
I have a simple table and form created, which allows the user to submit the pupils first name, surname, date of detention, and type of detention.
I would like a way, to bring up an error box, whenever a pupil has been given the same detention on the same day.
For example, If Joe Bloggs was given a Curriculum detention on 1/1/15, then another one, of the same date and detention could not be added.
However, i want to make it so he could recieve a different type of detention on the same day.
I searched around online, and have came across code to prevent, for example, i can prevent the First Name being blocked via the VBA below, however this means any pupil with the same name cannot be entered.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim StudentName As String
Dim TypeOfDetention As String
Dim stLinkCriteria As String
'Assign the entered customer name to a variable StudentName'
StudentName = Me.FirstName.Value
stLinkCriteria = "[First Name] = " & "'" & StudentName & "'"
If Me.FirstName = DLookup("[First Name]", "DetentionT", stLinkCriteria) Then
MsgBox "This customer, " & StudentName & ", has already been entered in database." _
& vbCr & vbCr & "Please check customer name again.", vbInformation, "Duplicate information"
Me.Undo 'undo the process and clear all fields
End If
End Sub
I hope this makes some sort of sense, and thanks beforehand for your time!
Joe
Thanks for taking the time to read this. I am quite new to Access, and i was wondering whether you could help me with something?
I work at a School and have been given the task to devise a detention sheet.
I have a simple table and form created, which allows the user to submit the pupils first name, surname, date of detention, and type of detention.
I would like a way, to bring up an error box, whenever a pupil has been given the same detention on the same day.
For example, If Joe Bloggs was given a Curriculum detention on 1/1/15, then another one, of the same date and detention could not be added.
However, i want to make it so he could recieve a different type of detention on the same day.
I searched around online, and have came across code to prevent, for example, i can prevent the First Name being blocked via the VBA below, however this means any pupil with the same name cannot be entered.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim StudentName As String
Dim TypeOfDetention As String
Dim stLinkCriteria As String
'Assign the entered customer name to a variable StudentName'
StudentName = Me.FirstName.Value
stLinkCriteria = "[First Name] = " & "'" & StudentName & "'"
If Me.FirstName = DLookup("[First Name]", "DetentionT", stLinkCriteria) Then
MsgBox "This customer, " & StudentName & ", has already been entered in database." _
& vbCr & vbCr & "Please check customer name again.", vbInformation, "Duplicate information"
Me.Undo 'undo the process and clear all fields
End If
End Sub
I hope this makes some sort of sense, and thanks beforehand for your time!
Joe