Password Form Code, Need Help

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

I created a table called tblPassword and created (2) fields. (1) ObjectName
which is in text format and set to primary key
(2) KeyCode which is in text format with a input mask of PASSWORD and
default value as administrator. and is not null as condition.

Next I created a form named frmPassword and made two fields (1) named Text0
with a input mask of PASSWORD
and (2) a command button which has as it's on click event, this code

If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
If Forms![frmPassword]!Text0 = Me!tbl.OrdersKeyCode.Value
Then

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

I want this form, frm Password to open a form called Orders if the password
is met.

What am I doing wrong, and how can I correct it ?

Thanks,

Dave
P.S. I looked at the code on the help site, but it didnt make any sense to
me.
 
Dave,
I created a table called tblPassword and created (2) fields. (1) ObjectName
which is in text format and set to primary key
(2) KeyCode which is in text format with a input mask of PASSWORD and
default value as administrator. and is not null as condition.

Next I created a form named frmPassword and made two fields (1) named Text0
with a input mask of PASSWORD

Two fields named Text0? The info you give us seems to be not very
accurate.
and (2) a command button which has as it's on click event, this code
If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
If Forms![frmPassword]!Text0 = Me!tbl.OrdersKeyCode.Value

There's the problem. You're using the name of a table field like a
control, and this is not possible. To compare the 2 values, you must
take the entered value and search for a record in the table having the
KeyCode equal to that value.

Here's some amended code (beware, untested!):

Dim strWhere As String

If IsNull(Me!Text0) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
'Put together the criteria for the table search
'Note the single quotes around the entered value,
'they are necessary because the table field is of
'text type.
strWhere = "KeyCode ='" & Me!Text0 & "'"

'Now look for a record in the table.
'If found, open the form
If Not IsNull(DLookup("ObjectName", "tblPassword", strWhere))
Then
'You don't say anything about a criteria for the form??
'If you don't need any, you don't need the stLinkCriteria
either
DoCmd.OpenForm "Orders"
End If
End If

Please look up the Help for the DLookup function.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Thanks ,

Dave

Emilia Maxim said:
Dave,
I created a table called tblPassword and created (2) fields. (1) ObjectName
which is in text format and set to primary key
(2) KeyCode which is in text format with a input mask of PASSWORD and
default value as administrator. and is not null as condition.

Next I created a form named frmPassword and made two fields (1) named Text0
with a input mask of PASSWORD

Two fields named Text0? The info you give us seems to be not very
accurate.
and (2) a command button which has as it's on click event, this code
If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
If Forms![frmPassword]!Text0 =
Me!tbl.OrdersKeyCode.Value

There's the problem. You're using the name of a table field like a
control, and this is not possible. To compare the 2 values, you must
take the entered value and search for a record in the table having the
KeyCode equal to that value.

Here's some amended code (beware, untested!):

Dim strWhere As String

If IsNull(Me!Text0) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
'Put together the criteria for the table search
'Note the single quotes around the entered value,
'they are necessary because the table field is of
'text type.
strWhere = "KeyCode ='" & Me!Text0 & "'"

'Now look for a record in the table.
'If found, open the form
If Not IsNull(DLookup("ObjectName", "tblPassword", strWhere))
Then
'You don't say anything about a criteria for the form??
'If you don't need any, you don't need the stLinkCriteria
either
DoCmd.OpenForm "Orders"
End If
End If

Please look up the Help for the DLookup function.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Back
Top