Password Check

T

ToyFixer

I have a database with the following objects
CostCentres - table : CostCentreCode(primary key), CostCentrePassword,+ some
more as columns

frmSelectCC - the login form which has :
cmbCostCentre - combo box to select the Cost Centre
txtPassword - text box to type in the password
frmSelectGLC - the form that should open up when the password is correct

I wrote the following code but the debugger stops at the first line (which
is shown below)

Could someone tell me where I got it wrong?

If Me.txtPassword.Value = DLookup("CostCentrePassword", "CostCentres",
"CostCentreCode = " & Me.cmbCostCentre.Value) Then
DoCmd.OpenForm "frmSelectGLC"
Else
MsgBox "Invalid Password! Please Try Again", vbOKOnly, "Budget
Collection System"
Me.txtPassword.SetFocus
End If
 
J

John Spencer

If CostCentreCode is a text field then you need to include quotes around the
value you are looking for

If Me.txtPassword.Value = DLookup("CostCentrePassword",
"CostCentres","CostCentreCode = """ & Me.cmbCostCentre.Value & """") Then

OR
If Me.txtPassword.Value = DLookup("CostCentrePassword",
"CostCentres","CostCentreCode = '" & Me.cmbCostCentre.Value & "'")

OR
If Me.txtPassword.Value = DLookup("CostCentrePassword",
"CostCentres","CostCentreCode = " & Chr(34) & Me.cmbCostCentre.Value &
Chr(34))

Of course, if there is no match then that code will have problems. So you
might want to use code like

If Me.txtPassword.Value = NZ(DLookup("CostCentrePassword",
"CostCentres","CostCentreCode = """ & Me.cmbCostCentre.Value &
""""),"zz22&&35") THEN


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top