Empty password causes an error

G

Guest

I'm new to ACCESS 2002 and I have a question on a string. I have a password box that requests the user to enter a password. If they enter a password the process works but if the password box is left empty it fails. I have the code below. Thanks for your help

This is in a module that calls the frmpassword form which then requests a password. If the password is correct it gives them access to another form

DoCmd.OpenForm "frmpassword", , , , , acDialog 'open form to enter passwor
strPassword = Forms!frmpassword!txtpwd 'Retrieve the password that was entered


'This shows me if I enter the password but not if it is empt
' It will fail if the box stays empty
' showme = Len(strPassword

'Does the password match if yes then open the frmDataEntry form
If Len(strPassword) > 0 The
If strPassword = "password" The
DoCmd.OpenForm "frmDataEntry
strPassword = "default
Els
MsgBox "Incorrect Password
End I
End I
Els
DoCmd.OpenForm "frmDataEntry
End I
 
G

George Nicholson

Len(strPassword) fails because you are asking for the length of Null.

Either test the textbox for Null before you assign it's value or use the NZ
function to substitute an empty string for Null.

If IsNull(Forms!frmpassword!txtpwd) Then Exit Sub
strPassword = Forms!frmpassword!txtpwd
......

OR
strPassword = nz(Forms!frmpassword!txtpwd,"")

--
George Nicholson

Remove 'Junk' from return address.


June said:
I'm new to ACCESS 2002 and I have a question on a string. I have a
password box that requests the user to enter a password. If they enter a
password the process works but if the password box is left empty it fails.
I have the code below. Thanks for your help.
This is in a module that calls the frmpassword form which then requests a
password. If the password is correct it gives them access to another form.
 

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

Similar Threads


Top