SetFocus not working (1 Viewer)

Momma

Member
Local time
Today, 23:40
Joined
Jan 22, 2022
Messages
114
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, 21:40
Joined
May 7, 2009
Messages
19,233
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, 23:40
Joined
Jan 22, 2022
Messages
114
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