determining if users Password is blank or standard

M

Martin

I tried to use the below code from a post by Joan Wild and it does not work.
I placed the code on the open event of my main switchboard form.

The VBA compiler did not like the line

Set ws = DBEngine.CreateWorkspace("tempws", CurrentUser(), "")

If the user has a password, you get error 3029. Not a valid account name or
password.

So I added an On Error event to try to capture the error. This does not
work either.
Whether the user has a blank or a valid password, the err that is returned
is always zero. I check the code by changing my password from blank to a
valid password through the Tools menu.

I have included my new code at the bottom of this post.

Thank you for your time.

Joan Wild said:
You can try to open a new workspace, passing CurrentUser() as the username
and "" as the password.
If you don't get an error, then the "" password is correct, and they have a
blank password.

Dim ws as Workspace
Set ws = DBEngine.CreateWorkspace("tempws", CurrentUser(),"")
If Err=0 then
'they have a blank password
'open a form for them to change their password
Else
'they don't have a blank password
'do nothing
End If

New code I tried.

Dim ws As Workspace

On Error GoTo ErrLogin

Set ws = CreateWorkspace("tempws", CurrentUser(), "")
Debug.Print CurrentUser()
Debug.Print err.number
If err = 0 Then
Stop
'users password is not blank
Else
Stop
'users has a blank password
End If

ErrLogin:
If err.number = 3029 Then
Resume Next
End If
 
T

Tom van Stiphout

On Thu, 6 Aug 2009 18:55:01 -0700, Martin

The error object gets reset after each line of any consequence.
Thus:
Dim x As Integer
On Error GoTo Error_Handler
x = 1 / 0
Debug.Print Err.Number

Exit_Handler:
Exit Sub

Error_Handler:
If Err.Number = 11 Then
Resume Next
Else
Resume Exit_Handler
End If

The above code will print 0, even though we clearly had a division by
zero. After all, the If statement in the error handler executed
successfully.
I think this is one of the few cases where On Error Resume Next makes
sense:
Dim x As Integer
On Error Resume Next
x = 1 / 0
Debug.Print Err.Number
if Err.Number = 11 then Msgbox "Arrrccchhh"

-Tom.
Microsoft Access MVP
 

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