Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2005, 12:51 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default continue topic: form lock down problem

Hi Dartcoach and ALL,
    I modified the codes you gave to me and complied it, there were no error in it. But looks like the forms(main form and sub form) still couldn't be locked down.
    I have two user "Admin1 and Admin2" who have admin rights. In the open event of the form, I put the codes as following:

   'Test if users are in admin group. If is true, has rights to modify both main form and subform.
   If (IsNull(Me.Creator)) Or CurrentUser() = "Admin1" Or CurrentUser() = "Admin2" Then
       Me.AllowAdditions = True
       Me.AllowDeletions = True
       Me.AllowEdits = True
       Me.Schedule_For_Bids.Form.AllowAdditions = True
       Me.Schedule_For_Bids.Form.AllowDeletions = True
       Me.Schedule_For_Bids.Form.AllowEdits = True
    Else
       Me.AllowAdditions = True
       Me.AllowDeletions = False
       Me.AllowEdits = False
       Me.Schedule_For_Bids.Form.AllowAdditions = False
       Me.Schedule_For_Bids.Form.AllowDeletions = False
       Me.Schedule_For_Bids.Form.AllowEdits = False

    End If
End Sub

When I tested it, if I login as Admin1 I couldn't view the form in design view except Admin2. For other users, they still can edit the records that were created by the Admin1 and Admin2.
Need suggestion and help again? Thank lots!

flyfish
__________________
flyfish
 
Old March 23rd, 2005, 01:42 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi ya flyfish!
1. Is your code in the on open of the main form?
2. Your if statement has all "Or"'s in it. Are you sure the creator should be null? What if you leave creator out of it?

Let me know.

Kevin

dartcoach
 
Old March 24th, 2005, 03:11 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Ya Flyfish!

Try this:

If (IsNull(Me.Creator)) Or CurrentUser = "Admin1" Or CurrentUser = "Admin2" Then
       Me.AllowAdditions = True
       Me.AllowDeletions = True
       Me.AllowEdits = True
       Me.Schedule_For_Bids.Form.AllowAdditions = True
       Me.Schedule_For_Bids.Form.AllowDeletions = True
       Me.Schedule_For_Bids.Form.AllowEdits = True
    Else
       Me.AllowAdditions = True
       Me.AllowDeletions = False
       Me.AllowEdits = False
       Me.Schedule_For_Bids.Form.AllowAdditions = False
       Me.Schedule_For_Bids.Form.AllowDeletions = False
       Me.Schedule_For_Bids.Form.AllowEdits = False

    End If
End Sub

When doing some research, I found that you don't need the () after currentuser.

See if this works for you and let me know!

Kevin


dartcoach
 
Old March 24th, 2005, 12:25 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
   I just tried the new code, it still doesn't work. Do you have an idea where the problem is?


Thank you again!


flyfish
 
Old March 24th, 2005, 10:41 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

PMJIH

For one thing, I recommend

If (IsNull(Me.Creator)) Or (CurrentUser() = "Admin1") Or (CurrentUser() = "Admin2") Then

Add the parens around the CurrentUser tests. Your syntax is correct. But I find that functions (such as IsNull or CurrentUser) can result in odd interpretations.

Troubleshooting tip:
Try breaking this into three different if statements using ElseIf.

If Isnull(me.Creator) then
   { unlock code }
elseif CurrentUser = "Admin1" then
   { unlock code }
elseif CurrentUser = "Admin2" then
   { unlock code }
else
   { lock code }
end if

I wouldn't leave it that way. But the idea is to be sure the rest of the code is working right. Or for that matter, just try one value at a time.

Another idea for your if... If all Admin users start with Admin you could try:

If (IsNull(Me.Creator)) Or (left(CurrentUser() & " ",5) = "Admin") Then

The '& " "' is to make sure CurrentUser has at least five characters. This check means you won't have to change your code if you add Amdin3.

One last tip...

Just in case Me.Creater is "" (an empty string) instead of null, try:

If (nz(Me.Creator,"") = "") Or (left(CurrentUser(),5) = "Admin") Then

The nz will convert null to an empty string. Then regardless whether your data is an empty string or null you'll pass that part of the test.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old March 28th, 2005, 03:15 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you suggestion.
I had tested codes you gave to me. I split the code to several IF and IFELSE, this doesn't work. I have several user who has admin rights, and the length of their names are vary. I couldn't set the length of the admin in the program. Any idea abouth this case? Thanks agagin!

flyfish
 
Old March 30th, 2005, 11:31 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

I need to know more about what "this doesn't work" means.

I think you need to do this...

Start at the beginning. Remove all the checks for user or who created the data. Make one pass that locks the form regardless of the user or creator. Test that. Make sure that does what you're expecting.

Make another pass that UNlocks the form regardless of the user or creator. Test that. Make sure that does what you're expecting.

Make another pass that checks for one specific Admin user. Test that if you are that user your form is unlocked. Test that if you are not that user the form is locked.

Remove that code and make another pass that checks for the data creator. Test the if the creator is null the form is unlocked. Test that if the creator is not null the form is locked.

Make another pass that combines the check for the Admin user and the creator. Run your tests.

Sometimes it's all a simple matter of what you expect to happen doesn't really happen. Perhaps the code is in the wrong event. Seems to me your code needs to be in the OnCurrent event since you're checking to see if the Creator is null.

Sometimes it's because we don't look at the data correctly. Are you sure that when you think the record should be unlocked that one of the conditions is true? I.e. it will only unlock if the current record has Creator = Null or an Admin user is logged on.

I don't know what "I couldn't set the length of the admin in the program" means. If Left(CurrentUser() & " ",5) doesn't work for your situation, don't use it. It was just a thought! There's nothing wrong with having a bunch of '(CurrentUser() = "Admin1") OR ...' in your test. There's better ways to code it. But if the OR's make sense to you, do that!

The first thing you have to do is make sure that you can get it right for the Creator and at least 1 Admin. The rest should be a piece of cake.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: forms lock down problem on Access97 flyfish Access 3 March 17th, 2005 09:09 PM
Re: forms lock down problem on Access97 flyfish Access 0 March 16th, 2005 03:34 PM
lock form problem flyfish Access 2 March 2nd, 2005 01:07 PM
break & continue problem. gredata C# 1 December 21st, 2004 05:38 AM
problem to "on caps lock progametically Abhinav_jain_mca General .NET 3 August 5th, 2004 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.