Hi guys!
I'm new in the forum and new Access user as well. I have a form where users can insert new data to a table through it. I kow how how to use Dlookup but not familiar with DCount. I want my vba code to prevent the user of using a combination of values that have already been entered. More specific...
My table with name "Company" has three columns that I need to check.
1) column 1 - Company Name
2) column 2 - Street
3) column 3 - Post Code
The user will be able to enter a new record with only one of these to be the same with a previous one. If a same combination of two of them already exist in the table a message of duplicated record will appear.
code: "What I tried, but does not work"
Help please!!!!
I'm new in the forum and new Access user as well. I have a form where users can insert new data to a table through it. I kow how how to use Dlookup but not familiar with DCount. I want my vba code to prevent the user of using a combination of values that have already been entered. More specific...
My table with name "Company" has three columns that I need to check.
1) column 1 - Company Name
2) column 2 - Street
3) column 3 - Post Code
The user will be able to enter a new record with only one of these to be the same with a previous one. If a same combination of two of them already exist in the table a message of duplicated record will appear.
code: "What I tried, but does not work"
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
Comment