0
votes

Where is the missing Operator?

Code:

If Nz(DLookup("Email", "Employees", "Email=" & Me![Email]), "") <> "" Then
    correo = DLookup("Email", "Employees", "Email=" & Me![Email])
2

2 Answers

0
votes

Email is going to be a string so your syntax should be:

If Nz(DLookup("Email", "Employees", "Email= '" & Me.Email & "'"), "") <> "" Then
    correo = DLookup("Email", "Employees", "Email= '" & Me.Email & "'")

Notice the single quotes added around the email address you are looking for.

-1
votes

Two things. First, it's ElseIf in VBA, not Else If (no space). Second, you have an extra End If at the end of the If block. See below:

Private Sub ResetButton_Click()

    Dim correo As String

        If Nz(Me.Email, "") = "" Then
            MsgBox "Email Empty. Please Enter a Valid Email Address.", vbInformation, "Email Empty"
            Me.Email.SetFocus
        ElseIf Nz(DLookup("Email", "Employees", "Email= '" & Me.Email & "'", "") <> "" Then
            correo = DLookup("Email", "Employees", "Email= '" & Me.Email & "'")
        End If

        If correo <> Me.Email Then
            MsgBox "Wrong Email Address. Please Use a Correct Email Address.", vbCritical, "Wrong Email Address"
            Me.Email.SetFocus
        Else
            DoCmd.Close
            DoCmd.OpenForm "UserVerificationPasswordReset"
        End If

End Sub