I have one table called tblCompany, which has four fields for telephone
numbers. The fields are: Phone, Phone2, Phone3, and Fax. And, four more
fields, which are: Ext (for extension), Ext2, Ext3, FaxExt. I want the code
to check for duplicates when entering or revising telephone numbers. I
entered the code below but it is not doing anything:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("[Phone]" And "[Ext]", "tblCompany", _
"[Phone2] = '" & Me.txtPhone2 & " And " & _
"[Ext2] = '" & Me.txtExt2 & " And " & _
"[Phone3] ='" & Me.txtPhone3 & " And " & _
"[Ext3] = '" & Me.txtExt3 & " And " & _
"[Fax] = '" & Me.txtFax & " And " & _
"[FaxExt] = '" & Me.txtFaxExt & " And " & _
"[CompanyID] <> " & Me.txtCompanyID) > 0 Then
MsgBox "Telephone number is already used.", , "Telephone number
search."
Cancel = True
End If
Exit Sub
End Sub
Am I missing the point? Should I be doing something different to check for
duplicate telephone numbers?
Help, please!
numbers. The fields are: Phone, Phone2, Phone3, and Fax. And, four more
fields, which are: Ext (for extension), Ext2, Ext3, FaxExt. I want the code
to check for duplicates when entering or revising telephone numbers. I
entered the code below but it is not doing anything:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("[Phone]" And "[Ext]", "tblCompany", _
"[Phone2] = '" & Me.txtPhone2 & " And " & _
"[Ext2] = '" & Me.txtExt2 & " And " & _
"[Phone3] ='" & Me.txtPhone3 & " And " & _
"[Ext3] = '" & Me.txtExt3 & " And " & _
"[Fax] = '" & Me.txtFax & " And " & _
"[FaxExt] = '" & Me.txtFaxExt & " And " & _
"[CompanyID] <> " & Me.txtCompanyID) > 0 Then
MsgBox "Telephone number is already used.", , "Telephone number
search."
Cancel = True
End If
Exit Sub
End Sub
Am I missing the point? Should I be doing something different to check for
duplicate telephone numbers?
Help, please!