Custom Login

D

Dave Ruhl

I am creating a custom login form for my Access database
(thanks again to Jeff Conrad - your tips & code worked
perfectly!) and I have one final hurdle to get over. I
would like to auto-fill my UserName field with the name
of the last person to login (as the Access login form
does). I assume this info is in the Windows Registry,
but I don't know how to retreive it. Can anyone give me
a hint please ? Thanks...
 
J

Jeff Conrad

Hi Dave,

Glad to hear my code helped in your project.

Interesting request, I had not considered that option.
I like a challenge so I played with this a bit.
I have met with *some* success.
You'll have to decide if it will work for you.

1. Follow this link:

http://www.mvps.org/access/api/api0015.htm

2. Copy/paste all the code to a new standard module.
Compile the code and save the module as modReadRegFile

3. Open up the unsecured database login form.
Put this code in the Form's Open event:

Me.txtUserName = fReturnRegKeyValue(HKEY_CURRENT_USER,
"Software\Microsoft\Office\8.0\Access\Settings", "Last User")

Make sure that all goes on ONE line!
You will need to adjust this obviously to your machine.
This was on a machine with Access 97 and a default install location.
Your best bet is to navigate down in the Registry hive for the Office/Access install information.
I'm thinking it should be pretty similar to the above, but I am out of the office and cannot test
this on other operating systems/access installations.
Please be careful in the Registry!! Look, but don't touch anything!

4. Compile the code in the form and save/close.

5. Open up the unsecured database and log into the secured database by entering the user name and
password in the text fields.

6. Close the secured database.

7. Open up the unsecured database again and the login form User Name field should display the name
you just used.
Hey, it works!!

But......
Now log in with a different User Name/Password.
Come back to the unsecured database and the login form will still show the first User Name you used.
Hummm....not good.

So, you will have to decide if this will work for you.
Presumably, a user will only be logging into the secured one from their workstation and only be
logging in as themselves. So this *could* work for you. I'm not sure.

There might be a way to write the information to the registry when the secured database starts up
(after a successful login of course), but I have not experimented with that option.
You could also write the value to a table in the unsecured database, but this might not account for
an unsuccessful login. The User Name field would then display an inaccurate name.
Another option *may* be to somehow pass in the User Name to the secured database and then write that
information to a table in the secured one. The unsecured one would read that value (presumably by
creating a temporary workspace) from the secured database and put that in the User Name field. Not
quite sure, however, if that would work. Seems like a lot of extra work to me though just to save
the user a few keystrokes.

Hope that helps,
 
D

Dave Ruhl

Once again, it's Jeff to the rescue !

Thanks Jeff, I'll give this a try on Monday and let you
know how it turns out.
-----Original Message-----
Hi Dave,

Glad to hear my code helped in your project.

Interesting request, I had not considered that option.
I like a challenge so I played with this a bit.
I have met with *some* success.
You'll have to decide if it will work for you.

1. Follow this link:

http://www.mvps.org/access/api/api0015.htm

2. Copy/paste all the code to a new standard module.
Compile the code and save the module as modReadRegFile

3. Open up the unsecured database login form.
Put this code in the Form's Open event:

Me.txtUserName = fReturnRegKeyValue(HKEY_CURRENT_USER,
"Software\Microsoft\Office\8.0\Access\Settings", "Last User")

Make sure that all goes on ONE line!
You will need to adjust this obviously to your machine.
This was on a machine with Access 97 and a default install location.
Your best bet is to navigate down in the Registry hive
for the Office/Access install information.
I'm thinking it should be pretty similar to the above,
but I am out of the office and cannot test
this on other operating systems/access installations.
Please be careful in the Registry!! Look, but don't touch anything!

4. Compile the code in the form and save/close.

5. Open up the unsecured database and log into the
secured database by entering the user name and
password in the text fields.

6. Close the secured database.

7. Open up the unsecured database again and the login
form User Name field should display the name
you just used.
Hey, it works!!

But......
Now log in with a different User Name/Password.
Come back to the unsecured database and the login form
will still show the first User Name you used.
Hummm....not good.

So, you will have to decide if this will work for you.
Presumably, a user will only be logging into the secured
one from their workstation and only be
logging in as themselves. So this *could* work for you. I'm not sure.

There might be a way to write the information to the
registry when the secured database starts up
(after a successful login of course), but I have not experimented with that option.
You could also write the value to a table in the
unsecured database, but this might not account for
an unsuccessful login. The User Name field would then display an inaccurate name.
Another option *may* be to somehow pass in the User Name
to the secured database and then write that
information to a table in the secured one. The unsecured
one would read that value (presumably by
creating a temporary workspace) from the secured
database and put that in the User Name field. Not
quite sure, however, if that would work. Seems like a
lot of extra work to me though just to save
 
J

Jeff Conrad

Once again, it's Jeff to the rescue !

Dang, forgot my cape again this morning!
The letters "AJ" on the back are starting to wear off though.
Thanks Jeff, I'll give this a try on Monday and let you
know how it turns out.

Ok, hope it works for you.
I may play with this some more on the weekend as well.
 
J

Joan Wild

Dave said:
I am creating a custom login form for my Access database
(thanks again to Jeff Conrad - your tips & code worked
perfectly!) and I have one final hurdle to get over. I
would like to auto-fill my UserName field with the name
of the last person to login (as the Access login form
does).
Another possibility is to bind your custom login form to a table that stores
the UserName.
 
D

Dave Ruhl

Hi Jeff, it worked perfectly! I'm using Access 2002 and
the name gets updated in the Registry from my login form.
I tested logging in with different names from my form and
from the default Access login and the most recent name
always shows up as the default either way.

One change I made to your code was to check for the
version of Access that is installed and build the 'key'
string dynamically. Most of our users are on Version
10.0 but some are on 11.0 so this works for both (or any
future versions).

Thanks again for the tips !!!
 
J

Jeff Conrad

Hi Jeff, it worked perfectly!

Excellent, that's good to hear!
I'm using Access 2002 and
the name gets updated in the Registry from my login form.
I tested logging in with different names from my form and
from the default Access login and the most recent name
always shows up as the default either way.

Can you say "Sweet"?
One change I made to your code was to check for the
version of Access that is installed and build the 'key'
string dynamically. Most of our users are on Version
10.0 but some are on 11.0 so this works for both (or any
future versions).

Ahhh, very nice Dave!
I had not even considered that option.
Thanks again for the tips !!!

You're welcome, glad to help.
 
Top