load a filtered form based on user login

  • Thread starter najah via AccessMonster.com
  • Start date
N

najah via AccessMonster.com

Hi all,

My question is:

I have a timesheet form that contains my depts employees timelog. One of the
fields is employeeID.

I've created a switchboard where the employee clicks on a command button and
it opens a form Timesheet which allows them to view/edit their time, However
they have the capabilities to view all 9 employee's records.

If possible, can someone help me with this task:
I've created logins and passwords for each employee

I need to create a code that does this:

If the user login=john doe then open a form so that it is filtered where the
employeeID =John Doe. This way they can only view their info.

I created an employee table/form that has [EmployeeID] and [EmployeeName]
fields and when setting up the login I just assigned the user name to match
the employeeID (consists of employees initials).
 
S

shanesullaway via AccessMonster.com

Hey Najah,

All you need to do is add criteria to the DoCmd.OpenForm line that opens your
timelog form, that equals the EmployeeID.

ie:

Dim stCriteria As String
stCriteria = "EmployeeID =" & Forms![NameOfLogInForm]![EmployeeID]
'this is if EmployeeID is numeric

use if text:
stCriteria = "EmployeeID ='" & Forms![NameOfLogInForm]![EmployeeID]
& "'"

DoCmd.OpenForm "FormNameBeingOpened",,stCriteria

HTH,
Shane

Hi all,

My question is:

I have a timesheet form that contains my depts employees timelog. One of the
fields is employeeID.

I've created a switchboard where the employee clicks on a command button and
it opens a form Timesheet which allows them to view/edit their time, However
they have the capabilities to view all 9 employee's records.

If possible, can someone help me with this task:
I've created logins and passwords for each employee

I need to create a code that does this:

If the user login=john doe then open a form so that it is filtered where the
employeeID =John Doe. This way they can only view their info.

I created an employee table/form that has [EmployeeID] and [EmployeeName]
fields and when setting up the login I just assigned the user name to match
the employeeID (consists of employees initials).
 
N

najah via AccessMonster.com

Thanks Shane,

I must let you know that I am fairly new to Access, so I am a little confused.
I created logins via the security wizard. Am I supposed to create a login
form and if so what fields do I include
Hey Najah,

All you need to do is add criteria to the DoCmd.OpenForm line that opens your
timelog form, that equals the EmployeeID.

ie:

Dim stCriteria As String
stCriteria = "EmployeeID =" & Forms![NameOfLogInForm]![EmployeeID]
'this is if EmployeeID is numeric

use if text:
stCriteria = "EmployeeID ='" & Forms![NameOfLogInForm]![EmployeeID]
& "'"

DoCmd.OpenForm "FormNameBeingOpened",,stCriteria

HTH,
Shane
[quoted text clipped - 18 lines]
fields and when setting up the login I just assigned the user name to match
the employeeID (consists of employees initials).
 
J

Joan Wild

If you are using the built-in security then set the record source of the
Timesheet form to
a query where the criteria under EmployeeID is =CurrentUser()

--
Joan Wild
Microsoft Access MVP
Thanks Shane,

I must let you know that I am fairly new to Access, so I am a little
confused. I created logins via the security wizard. Am I supposed to
create a login form and if so what fields do I include
Hey Najah,

All you need to do is add criteria to the DoCmd.OpenForm line that
opens your timelog form, that equals the EmployeeID.

ie:

Dim stCriteria As String
stCriteria = "EmployeeID =" &
Forms![NameOfLogInForm]![EmployeeID] 'this is if EmployeeID is
numeric

use if text:
stCriteria = "EmployeeID ='" &
Forms![NameOfLogInForm]![EmployeeID] & "'"

DoCmd.OpenForm "FormNameBeingOpened",,stCriteria

HTH,
Shane
[quoted text clipped - 18 lines]
fields and when setting up the login I just assigned the user name
to match the employeeID (consists of employees initials).
 
N

najah via AccessMonster.com

Joan,

Thanks for your reply. I am glad to hear from you for I am new to access as
well as access monster and as I read through the various forums I find you
very knowledgeable.

Let me explain in detail what goes on with this db.

On my switchboard there is a command button to enter time which launches the
Timesheet form in add mode. The employee selects his name from a drop down
and enters a start and end date to reflect their biweekly time. They then
enter their details of a workday in a subform entitled Timesheet Hours. After
order entry their is a button on the form that opens a report which allows
for printing. The recordsource for this form is a table entitled Timesheet.

Their is also a button on the switchboard that allows them to view/edit their
timesheet in the event they come across an error once they have printed their
timesheet.

of course, it is when they view/edit their timesheet is when i need the form
to open for them to view just their time log.

I created a query with the criteria for EmployeeID=CurrentUser() and changed
the recordsource to match the
query so when I click the command button on the switchborad to edit/view
timesheet it opens based on the user. However when I click the button to
enter time the form doesn't load because by changing the recordsource to
match the query it affected Timesheet in add mode.

Also, I need the supervisors to be able to view all the records not just
theirs and with employeeID=currentuser that limits their view also.

I hope I clarified this, please help me it is driving me crazy

Najah


Joan said:
If you are using the built-in security then set the record source of the
Timesheet form to
a query where the criteria under EmployeeID is =CurrentUser()
Thanks Shane,
[quoted text clipped - 32 lines]
Message posted via AccessMonster.com
 
J

Joan Wild

najah said:
On my switchboard there is a command button to enter time which
launches the Timesheet form in add mode. The
recordsource for this form is a table entitled Timesheet.

Their is also a button on the switchboard that allows them to
view/edit their timesheet in the event they come across an error once
they have printed their timesheet.

I created a query with the criteria for EmployeeID=CurrentUser() and
changed the recordsource to match the
query so when I click the command button on the switchborad to
edit/view timesheet it opens based on the user. However when I
click the button to enter time the form doesn't load because by
changing the recordsource to match the query it affected Timesheet in
add mode.

This makes no sense. You said the enter timesheet was based on a table
called Timesheet. The view/edit timesheet you said is based on a query.
Changing the query has no impact on the table, so should not affect your
enter timesheet. Please clarify.
Also, I need the supervisors to be able to view all the records not
just theirs and with employeeID=currentuser that limits their view
also.

You can set the recordsource at runtime. There is a function in the
security FAQ you can use to determine if the currentuser is a member of a
security group. Use that to determine if they are a supervisor. i.e.

If faq_IsUserInGroup("Supervisors",CurrentUser) then
Me.RecordSource = "SELECT * FROM TimeSheet"
Else
Me.RecordSource = "SELECT * FROM TimeSheet WHERE [EmployeeID] = " &
chr(34) & CurrentUser() & chr(34)
End If

You could put that in the open event of the view/edit form.
 

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