hi guys!
It sounds easy but still don't know how to do it..Initially, I'm a new Access user and not very good in vba!
I have a form where the users are going to enter new data. This form is looking at a table and I don't want the users to be permitted to enter duplicated records in the table. I can do it with Dlookup function, but now I want to prevent entring data when a combination of criteria is met. As far as I know Dlookup works only for one criteria. More specific..
My form is called 'Companyform', the table 'Company' and the three fields in the table that I want to check are: 'Company Name', 'Street' and 'Town'. the user will be prevented to enter a new record when at least two of them are the same with a past record.
Any helpppppppp?????:banghead:
what I tried but I receive run time error:
code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Street As String
Dim Company_Name As String
Dim Town As String
If DCount("[Street]", "Company", "[Company_Name]='" & Me!Company_Name & "' AND [Town]='" & Me!Town & "'") > 0 Then
msg = "You already have that OrderID and Customer_ID combination" & vbNewLine
msg = msg & "The record will now be undone"
MsgBox msg, vbExclamation, "System Duplication Message"
Me.Undo
Cancel = True
End If
End Sub
It sounds easy but still don't know how to do it..Initially, I'm a new Access user and not very good in vba!
I have a form where the users are going to enter new data. This form is looking at a table and I don't want the users to be permitted to enter duplicated records in the table. I can do it with Dlookup function, but now I want to prevent entring data when a combination of criteria is met. As far as I know Dlookup works only for one criteria. More specific..
My form is called 'Companyform', the table 'Company' and the three fields in the table that I want to check are: 'Company Name', 'Street' and 'Town'. the user will be prevented to enter a new record when at least two of them are the same with a past record.
Any helpppppppp?????:banghead:
what I tried but I receive run time error:
code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Street As String
Dim Company_Name As String
Dim Town As String
If DCount("[Street]", "Company", "[Company_Name]='" & Me!Company_Name & "' AND [Town]='" & Me!Town & "'") > 0 Then
msg = "You already have that OrderID and Customer_ID combination" & vbNewLine
msg = msg & "The record will now be undone"
MsgBox msg, vbExclamation, "System Duplication Message"
Me.Undo
Cancel = True
End If
End Sub