By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

Find a record when Form opens

P: n/a
Hello all

My code used to work, but now its not working any more. What I am
trying to do is find the current user when a forms open. This is the
code that used to work:

If faq_IsUserInGroup("Admins", CurrentUser) Then
Me.RecordSource = "SELECT * FROM Employees"
DoCmd.FindRecord (CurrentUser)
<----------------------------------------------------
Me.Label50.Visible = True
Me.ViewReports.Visible = True
Me.AddDeleteExpenseTypes.Visible = True
Me.Label48.Visible = True
Me.Line69.Visible = True
Me.Label52.Visible = True
Me.Line72.Visible = True
Else
Me.Label50.Visible = False
Me.ViewReports.Visible = False
Me.AddDeleteExpenseTypes.Visible = False
Me.NavigationButtons = False
Me.Label48.Visible = False
Me.Line69.Visible = False
Me.Label52.Visible = False
Me.Line72.Visible = False
Me.manageu.Visible = False
End If

Basically is a user is under the Admins group he can see all the
records/users...otherwise the rest of the user groups can only see his
records.

DoCmd.FindRecord (CurrentUser) suppose to find the currentuser, so the
form will open showing his information, but its NOT working

Any ideas???

Aug 31 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
what's the problem with passing the filter in the Open event of the
form? You can pass a valid where clause, in your case
[SomeField]=CurrentUser

Aug 31 '06 #2

P: n/a

pi********@hotmail.com wrote:
what's the problem with passing the filter in the Open event of the
form? You can pass a valid where clause, in your case
[SomeField]=CurrentUser
I dont quite understand what you mean. I dont want only "some field" I
want all the form to display only the information of the currentuser.

Can you explain me a lil bit more please, thanks

Aug 31 '06 #3

P: n/a

Ok, I see what you mean. But I cant apply that technique in here. The
form has a subform. I want to be able to display only the record from
the currentuser, in the form so I will automatically show the
information of that currentuser in the subform.

Any other ideas

Aug 31 '06 #4

P: n/a
Public Sub OpenFilteredForm()
DoCmd.OpenForm "frmMyFormName", acNormal, ,
"[UserNameFieldFromSourceTable]=" & CurrentUser
End Sub

Aug 31 '06 #5

P: n/a
Code like this should work:

If faq_IsUserInGroup("Admins", CurrentUser) Then
Me.RecordSource = "SELECT * FROM Employees"
else
Me.RecordSource = "SELECT * FROM Employees WHERE
Employees.Username=" & CurrentUser
End If

then when someone opens the form, the admins will see all the records,
but the other employees will only see their records. The catch is that
you have to record the user's name somewhere in the record.

Filtering the subform depends on the main form/subform
LinkChild/LinkMaster properties. But you could set the rowsource of
the subform to:
SELECT...FROM...WHERE Employee.Username=CurrentUser

Aug 31 '06 #6

P: n/a

What about... forget all I said. And

You create a new User so he can use the database. This user has Admin
rights.
He logon to the application, and the form (to enter his information,
name, address, etc.) needs to be blank when it loads (because he is a
new user), he enter all his info and save his info
BUT
if the user already exist....he logon to the application and the form
(with the information) should load with his information (because he is
an existing user, and he already complete this step). Even if there are
20 users that have already completed the information form...the user
that logon should see HIS information when the form loads, in other
words I dont want to be using the navigation buttons to find a
particular user....

How would you do that....again forget all that I said in the previous
post, I just want to see if there is a better way to do this, because
the way i am trying to do it its not working quite well

Everything is working good but imagine if there are 50 users within the
application. The president logon to complete an expense report (thats
what this application is about) he does not want to be using the
navigation buttons to find his "profile" he just want to see directly
his information when the application loads, so he can fill his expense
report and print it w/o losing much time, do you understand what I
mean?

Thank you in advance

Aug 31 '06 #7

P: n/a

erick-flores wrote:
What about... forget all I said. And

You create a new User so he can use the database. This user has Admin
rights.
BAD design. That means that user can modify/delete ANYTHING in your
database, and completely wreck it. (Well, unless it's an MDE).
He logon to the application, and the form (to enter his information,
name, address, etc.) needs to be blank when it loads (because he is a
new user), he enter all his info and save his info
So base all the forms on queries, and filter for =CurrentUser() Then
the user can't see anything else.
Everything is working good but imagine if there are 50 users within the
application. The president logon to complete an expense report (thats
what this application is about) he does not want to be using the
navigation buttons to find his "profile" he just want to see directly
his information when the application loads, so he can fill his expense
report and print it w/o losing much time, do you understand what I
mean?
If you have the president's user account as a member of different
groups, you can give him different rights, and use a function or
whatever you want in the splash screen or whatever to determine what
objects the current user can use. If you got a copy of the form in the
Developer Handbook that mimics an Access db with all the containers
(for queries etc), then you could totally control what the users could
do, and it would look just like a normal Access DB, but they can only
use what you say they can.

This sort of makes sense. So the president will have different rights
than other users, because he is a member of more groups than other
users. So he'll have more menu choices. A new user? You would have
to create an account for this person to use the database if it's
secured. Or is it not? If it isn't the users/groups is worthless.
If you wanted to store all the name/address stuff in the database, you
could use CurrentUser to filter what the person sees in the db.

Aug 31 '06 #8

P: n/a
The user was just an example. I do have different groups to access the
DB. Some can look at all the users other can look only at their info.
Groups have different permissions to tables/forms/reports and all that.
Thats all taking care of.

I will check tomorrow to see if I can fix my problem

Thank you

Sep 1 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.