problem using DlookUp

akshayjoshi222

Registered User.
Local time
Tomorrow, 04:42
Joined
Mar 14, 2010
Messages
11
i have table "pdp" containing fields -

EmpName,EmpId,EmpPass
i have a form "chng password" containing fields-

textbox with name txtNewEmpPass

command button for changing the EmpPass

i want DLookUp To return the value of EmpPass from the table "pdp"
,it should compare the value with txtNewEmpPass(selection criteria)

i am using this code-

OldPass = DLookup("[EmpPass]", "pdp", "[EmpPass]=" & "'" & txtNewEmpPass & "'")

and if i use this code-
OldPass = DLookup("[EmpPass]", "pdp", "EmpPass='" & txtNewEmpPass.Value & "'")
it generates error invalid use of null
 
Last edited:
i want DLookUp To return the value of EmpPass from the table "pdp"
,it should compare the value with txtNewEmpPass(selection criteria)

i am using this code-

OldPass = DLookup("[EmpPass]", "pdp", "[EmpPass]=" & "'" & txtNewEmpPass & "'")
The DLookup is not necessarily used for comparison. It's used to check if a value exists. What you would then do is check the result returned Is Null or not. The value returned if there's no existing record based on your criteria is Null.

and if i use this code-
OldPass = DLookup("[EmpPass]", "pdp", "EmpPass='" & txtNewEmpPass.Value & "'")
it generates error invalid use of null
Use this code instead and check against Null. However, you cannot assign Null to a string type variable (i.e. OldPass in your case). If you wanted to use the DLookup in that fashion you could use a variant variable.
Code:
If IsNull(DLookup("[EmpPass]", "pdp", "EmpPass='" & txtNewEmpPass.Value & "'") Then
    Msgbox "No match found"
Else
    Msgbox "Match found"
End If

To get the value if it's not Null use a variant type variable as explained above:
Code:
Dim OldPass as Variant
OldPass = DLookup("[EmpPass]", "pdp", "EmpPass='" & txtNewEmpPass.Value & "'")
 
thnks,but i want a command to return the value of EmpPass from table "pdp" and store that Value in OldPass,is it possible
 

Users who are viewing this thread

Back
Top Bottom