SetFocus not working

Momma

Member
Local time
Today, 19:13
Joined
Jan 22, 2022
Messages
132
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
 
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
 
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

Back
Top Bottom