SetFocus not working (1 Viewer)

Momma

Member
Local time
Today, 17:19
Joined
Jan 22, 2022
Messages
70
I want to set the focus on the Email field if already exist. Not getting an error but it goes to the next field instead.

Code:
Private Sub Email_AfterUpdate()
    If DCount("*", "tblContacts", "[Email] = '" & Me.Email & "'") > 0 Then
        MsgBox "This Email already exists:-" & vbCrLf, vbOKOnly + vbExclamation
        Me.Undo
        Me.Email.SetFocus
    End If
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:19
Joined
May 7, 2009
Messages
16,421
use BeforeUpdate event:
Code:
Private Sub Email_BeforeUpdate(Cancel As Integer)
    Cancel = (DCount("*", "tblContacts", "[Email] = '" & Me.Email & "'") <> 0)
    If Cancel  Then
        MsgBox "This Email already exists:-" & vbCrLf, vbOKOnly + vbExclamation
    End If
End Sub
 

Momma

Member
Local time
Today, 17:19
Joined
Jan 22, 2022
Messages
70
use BeforeUpdate event:
Code:
Private Sub Email_BeforeUpdate(Cancel As Integer)
    Cancel = (DCount("*", "tblContacts", "[Email] = '" & Me.Email & "'") <> 0)
    If Cancel  Then
        MsgBox "This Email already exists:-" & vbCrLf, vbOKOnly + vbExclamation
    End If
End Sub
Thank you for your reply. It is working 😊
 

Users who are viewing this thread

Top Bottom