Solved Reset password screen (1 Viewer)

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Just saw post #13 together with your edit. Pleased to see you got it working without me having to check anything.....
When you originally got those errors, were you trying to run it from the zip file? That won't work for any Access file! :rolleyes:

Anyway, it seems you've now got yours working with the help of Gasman :)
Yes, I hadn't saved it properly onto my laptop before having a look. It looks looks like a nice bit of programming, well done! Although I have got it to work, I may still be seeking the help of the Gasman if things get a bit confusing... and they usually do! 🤪
Cheers mate (y)
M
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:59
Joined
Feb 19, 2002
Messages
42,973
The sample I posted does EXACTLY what you want and it works.
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
The sample I posted does EXACTLY what you want and it works.
Thanks, Pat. I'm going to have a look at the one you sent me over the next couple of days. I had a quick look earlier and it looks really good. I'm pretty sure that, between all of the helpful advice posted in response to my original question, I'm going to learn a fair bit from this experience.
Thanks again for taking the time to help :)
M
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:59
Joined
Feb 19, 2002
Messages
42,973
You're welcome. The example also includes simple security and a custom switchboard as well as a modified version of the Access Switchboard based on the last version that used VBA rather than embedded macros.
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
You are welcome to use my free password login app which includes the feature you want:
i.e. force all new users to change the default password on first login.
As an option, you can also require users to reset their password after a specified number of days.
See http://www.mendipdatasystems.co.uk/password-login/4594469149
Hi again @isladogs.
Hope you don't mind me contacting you about your password and login database you helped me with a couple of weeks ago. Having played with it for a while now in relation to my own database, I noticed that there is a field for Access Level included in the Users table and was wondering how difficult it would be to use that to determine whether or not a command button on a form is displayed? Basically, I would like managers to log in and have access to all the Manager Section from the switchboard using a command button, but if a general user logs in that "Manager Section" button is either disabled or not visible.
Thanks
M :)
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
Hi.
Its very simple to do.

First add this function to modFunctions:
Code:
Public Function GetAccessLevel()
   'gets AccessLevel for current user
   GetAccessLevel = Nz(DLookup("AccessLevel", "tblUsers", "UserName = '" & GetUserName & "'"), 0)
End Function

Now add code similar to the following to the Form_Load event:

Code:
Select Case GetAccessLevel

Case 1 'standard user
  Me.cmdButton1.visible=False
  Me.cmdButton2.visible=False
  Me.cmdButton3.visible=True
  Me.cmdButton4.visible=True

Case 2 'manager
  Me.cmdButton1.visible=True
  Me.cmdButton2.visible=True
  Me.cmdButton3.visible=True
  Me.cmdButton4.visible=True

  Case 3 'admin
  'other code here if needed

  End Select

If preferred use .Enabled=False & .Enabled=True instead

If you have a lot of controls, you can simplify the code by assigning the same value to the Tag property of all controls that should be treated the same e.g.

Code:
Select Case GetAccessLevel

Case 1 'standard user
  ShowControls True, "A"
  ShowControls False, "B"
  EnableControls False, "C"

Case 2 'manager
  ShowControls True, "A", "B"
  EnableControls True, "C"

Case 3 'admin
  'other code here if needed

End Select

NOTE You will need functions ShowControls, EnableControls & LockControls.
These are included in my module modControlState of my example SetControls database that demonstrates this approach
 
Last edited:

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Hi.
Its very simple to do. Add code similar to the following to the Form_Load event:

Code:
Select Case AccessLevel 'note - there is no space in the field name

Case 1 'standard user
  Me.cmdButton1.visible=False
  Me.cmdButton2.visible=False
  Me.cmdButton3.visible=True
  Me.cmdButton4.visible=True

Case 2 'manager
  Me.cmdButton1.visible=True
  Me.cmdButton2.visible=True
  Me.cmdButton3.visible=True
  Me.cmdButton4.visible=True

  Case 3 'admin
  'other code here if needed

  End Select

If preferred use .Enabled=False & .Enabled=True instead

If you have a lot of controls, you can simplify the code by assigning the same value to the Tag property of all controls that should be treated the same e.g.

Code:
Select Case AccessLevel

Case 1 'standard user
  ShowControls True, "A"
  ShowControls False, "B"
  EnableControls False, "C"

Case 2 'manager
  ShowControls True, "A", "B"
  EnableControls True, "C"

Case 3 'admin
  'other code here if needed

End Select

NOTE You will need functions ShowControls, EnableControls & LockControls.
These are included in my module modControlState of my example SetControls database that demonstrates this approach
Ok, so I have experimented with your first code suggestion by creating a form with 4 command buttons, each named cmdButton1 etc (I am doing this on your original PasswordLogin_RC4_v5.3 database). I added the code to the "on load" event of the form, but when it loads all 4 buttons are still displayed. The tblUsers has a mix of users with AccessLevel 1, 2 or 3 and I have added the required code to the Case 3 section of the code you provided. What do you think I may be missing?
Cheers
M
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
Set all 4 controls to be hidden by default in the form design OR add code to do that before the Select Case statement
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Set all 4 controls to be hidden by default in the form design OR add code to do that before the Select Case statement
I set them as hidden in the design, but now they don't appear regardless of which user is logged in. Do I need to somehow include where the code picks up the AccessLevel field value from?
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
Apologies. I didn't check properly

Add this function to modFunctions:
Code:
Public Function GetAccessLevel()
   'gets AccessLevel for current user
   GetAccessLevel = Nz(DLookup("AccessLevel", "tblUsers", "UserName = '" & GetUserName & "'"), 0)
End Function

Now modify the code I gave you in post #26 to use
Code:
Select Case GetAccessLevel
....etc

I've now corrected that post
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Apologies. I didn't check properly

Add this function to modFunctions:
Code:
Public Function GetAccessLevel()
   'gets AccessLevel for current user
   GetAccessLevel = Nz(DLookup("AccessLevel", "tblUsers", "UserName = '" & GetUserName & "'"), 0)
End Function

Now modify the code I gave you in post #26 to use
Code:
Select Case GetAccessLevel
....etc

I've now corrected that post
Nope, still no joy. I have set up 3 new users, each with their own access level (1, 2 and 3), but it doesn't matter which one I log in as, the switchboard form is still blank even though the frmSessions shows the user as still logged in.
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
I can assure you the modified definitely works so the issue must be something to do with the form you are using or the code you have entered.

In the VBE immediate window try typing the following on two separate lines then press Enter after each item:
?GetUserName
?GetAccessLevel
Do you get the output expected for each of those?

You mention its a switchboard form.
You need to be aware that the built in Access switchboard form (which I never use) is a non-standard form.
Suggest you re-try this using a standard form with various buttons.
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
I can assure you the modified definitely works so the issue must be something to do with the form you are using or the code you have entered.

In the VBE immediate window try typing the following on two separate lines then press Enter after each item:
?GetUserName
?GetAccessLevel
Do you get the output expected for each of those?

You mention its a switchboard form.
You need to be aware that the built in Access switchboard form (which I never use) is a non-standard form.
Suggest you re-try this using a standard form with various buttons.
The VBA immediate results were what I expected, so it looks like it's something to do with the form. I'm not sure what you mean by the built in Access switchboard though. I created the frmSwitchboard the way I always create forms - Create... Form Design... then add the command buttons etc. Is this not standard? It's basically just a blank form with 4 command buttons on it, each named cmdButton1 etc. The buttons themselves don't do anything when clicked, as I just wanted to get the concept and functionality working before I start mucking about with my proper DB.
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
I can't tell what your form or code is like so its difficult to ascertain what your issue is
Suggest you upload the database you are using - remove any confidential data
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Here it is. It's really just the DB you recommended I try a couple of weeks ago, with the extra switchboard form added to help me understand how things should work. I have removed the existing users that you had on your version and added 3 users with their own access level (which is where I want to go when I implement the system on my proper DB).
On another note, just like to say how grateful I am for your help on this. I'm learning a fair bit from your advice, which is ultimately what I'm hoping to achieve. Do you have any suggestions on where/how I may improve my VBA knowledge (any YouTube channels etc)?
Cheers
M
 

Attachments

  • PasswordLogin_RC4_v5.3.accdb
    968 KB · Views: 134

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,186
Hi
You had hidden all 4 buttons in the property sheet! (Visible=false)

I changed that & ran the code & it works exactly as planned
To make it easier to check, I've added a message box to show UserName & AccessLevel when you open your frmSwitchboard.
Just remove that MsgBox line when you're ready...

NOTE: I've removed all records from tblLoginSessions to make your testing easier

As for YouTube videos, I recommend those by Steve Bishop. He has a complete series of over 100 Access videos covering all levels from absolute beginner through to advanced. I've only watched a few but they were very good.
Or there is a similar series of Access videos by Richard Roth

BTW the code in the PasswordLogin app is quite complex so don't worry if you find some of it quite difficult to understand if you are a beginner with VBA

Hope that helps
 

Attachments

  • Modified_PasswordLogin_RC4_v5.3_mistermarty.zip
    69.4 KB · Views: 121

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Hi
You had hidden all 4 buttons in the property sheet! (Visible=false)

I changed that & ran the code & it works exactly as planned
To make it easier to check, I've added a message box to show UserName & AccessLevel when you open your frmSwitchboard.
Just remove that MsgBox line when you're ready...

NOTE: I've removed all records from tblLoginSessions to make your testing easier

As for YouTube videos, I recommend those by Steve Bishop. He has a complete series of over 100 Access videos covering all levels from absolute beginner through to advanced. I've only watched a few but they were very good.
Or there is a similar series of Access videos by Richard Roth

BTW the code in the PasswordLogin app is quite complex so don't worry if you find some of it quite difficult to understand if you are a beginner with VBA

Hope that helps
That's fab, thanks. I hid the 4 buttons because I thought that's what you meant in your previous message yesterday ("Set all 4 controls to be hidden by default in the form design..."). Anyhow, I'm glad (and grateful) that you spotted my mistake.
Thanks also for the recommendations. I've been looking at Steve Bishop's stuff, I'm on about episode 35 at the moment. I'll have a look at the Roth ones too.
Cheers buddy
M
 

mistermarty

Member
Local time
Today, 19:59
Joined
Oct 31, 2020
Messages
41
Hi. Just another quick question about the Modified_PasswordLogin_RC4_v5.3_mistermarty you sent me the other day... are the options for forcing users to reset their passwords (ChangePWD and ExpireDays) active? I have tried ticking the box for one of the users and set the ExpireDays to 1 for another, but neither prompted a password change.
Ta
M

Edit
Ignore the above. I was being a biff! It works :)
 
Last edited:

Users who are viewing this thread

Top Bottom