Adding a Message Box ?

S

SA2002

I am using the below code to check for duplicate records between three email
fields. Is there a way to add a message box so that when a person enters a
duplicate email address in any of the fields (email1, email2, email3) that a
msg box will pop up?


Private Sub txtEmail1_BeforeUpdate(Cancel As Integer)

If Duplicated Then DoCmd.CancelEvent
End Sub

Private Sub txtEmail2_BeforeUpdate(Cancel As Integer)

If Duplicated Then DoCmd.CancelEvent
End Sub

Private Sub txtEmail3_BeforeUpdate(Cancel As Integer)

If Duplicated Then DoCmd.CancelEvent
End Sub

Private Function Duplicated() As Boolean
Dim EM1, EM2, EM3 As String

EM1 = Nz(txtEmail1, "NoEmail1")
EM2 = Nz(txtEmail2, "NoEmail2")
EM3 = Nz(txtEmail3, "NoEmail3")

If EM1 = EM2 Or EM2 = EM3 Or EM3 = EM1 Then
Duplicated = True
Else
Duplicated = False
End If
End Function
 
D

Dennis

Private Function Duplicated() As Boolean
Dim EM1, EM2, EM3 As String

EM1 = Nz(txtEmail1, "NoEmail1")
EM2 = Nz(txtEmail2, "NoEmail2")
EM3 = Nz(txtEmail3, "NoEmail3")

If EM1 = EM2 Or EM2 = EM3 Or EM3 = EM1 Then
msgbox "Duplicate E-mail address entered"
Duplicated = True
Else
Duplicated = False
End If
End Function
 
S

Stefan Hoffmann

hi Dennis,

The declaration syntax in VBA is slightly different here than in VB.
This declares EM1 and EM2 as Variant, not as String as it would in VB.

So you need

Dim EM1 As String, EM2 As String, EM3 As String

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top