473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Filter the report based on the current user.

Dear Friends,

I am using A2010 Version.I have a report which is displaying the data of all the users, which I want to rectify and display only the data of the current user.

Now to give you basic info:
I have 2 tables:
1)AddUser(EmployeeId{Numeric},Job Title,SecurityId....)
2)Tasks(ID,EmployeeId,Title,Description,Start Date, Due Date,..)

Now when the current user click on the command button, it redirect to the report. Report contains Fields like
EmployeeId,EmployeeName,Title,Description,Start Date,Due Date.

Now EmployeeId and EmployeeName is displayed through the combobox query in Row Source.
Please note: EmployeeId and all the details are fetched from "Tasks" table, while EmployeeName is fetched from "Contacts" table.

At last , I want to filter the data based on the EmployeeId.

I surfed a lot and came across so many solutions but neither are solving my problem, or I am not getting a clear idea how to do that.

Please help me out.

Looking forward for helpful reply. :)
May 14 '15 #1
31 2463
Seth Schrock
2,965 Expert 2GB
The exact answer would depend on how you are storing the currently logged in employee. However, the general idea would be something like the following:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="Report_Name", View:=acViewPreview, WhereCondition:="EmmployeeID = " & GetEmployeeID
May 14 '15 #2
Hi Seth,

Thanks for your reply.

I have tried it. But the report is not displaying any records in it.
May 14 '15 #3
jforbes
1,107 Expert 1GB
Seth's approach is the most straightforward and easiest way of doing what you are asking about, so if it is not working for you, you may want to post the code you are using and we can help you get it working.
May 14 '15 #4
Seth Schrock
2,965 Expert 2GB
Also, as a troubleshooting technique, try the following:
Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria As String
  2.  
  3. strCriteria = "EmmployeeID = " & GetEmployeeID
  4. Debug.Print strCriteria
  5.  
  6. DoCmd.OpenReport ReportName:="Report_Name", View:=acViewPreview, WhereCondition:=strCriteria
This will post exactly what the report is filtering based on in the Immediate window. Please copy that into your post. If you don't see the Immediate window, press Ctrl + G to view it.
May 14 '15 #5
Hi Seth,

Thank you for your reply.


I have tried implementing your method. But the problem persists.

It can be because the way I fetch the data from the table.

What I am doing is:
I am using Combobox to fetch EmployeeId and EmployeeName in my report.
It works fine for displaying all users data. But not for current user.

I tried your way, but blank report is coming.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Individualreport_Click()
  2. 'DoCmd.OpenReport ReportName:="IndividualTask", View:=acViewPreview, WhereCondition:="EmployeeID = " & txtUserID
  3.  Dim strCriteria As String
  4.  
  5.  strCriteria = "EmployeeId = " & txtUserID
  6.  Debug.Print strCriteria
  7.  
  8.  DoCmd.OpenReport ReportName:="IndividualTask", View:=acViewPreview, WhereCondition:=strCriteria
  9.  
  10.  
  11. End Sub
  12.  
Also, if it helps this way, I tried using other method also earlier for filtering the data(which I found in one site)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Individualreport_Click()
  3. 'DoCmd.ApplyFilter , "AddUser.EmployeeId = " & Me.txtUserID
  4.  
  5.  
  6.     Dim strWhere As String
  7.     If Me.Dirty Then Me.Dirty = False 'save any edits
  8.      If Me.FilterOn Then strWhere = Me.Filter
  9.     DoCmd.OpenReport "IndividualTask", acViewPreview, , strWhere
  10.  DoCmd.OpenReport "IndividualTask", acViewReport, Me.Filter
  11.     On Error GoTo ErrHandler
  12.     DoCmd.OpenReport ReportName:="IndividualTask", View:=acViewPreview, _
  13.         WhereCondition:="[Contacts Extended].EmployeeId=" & Me.txtUserID    '=" & Chr(34) & Me.ID & Chr(34)
  14. 'DoCmd.OpenReport "IndividualTask", acViewPreview, , "[Tasks].EmployeeId = " & Me.txtUserID
  15.     Exit Sub
  16.  
  17. ErrHandler:
  18.     ' Don't show error message if report was canceled
  19.     If Err <> 2501 Then
  20.         MsgBox Err.Description, vbCritical
  21.     End If
  22.  
  23. End Sub
  24.  
Please don't mind but also highlight that what should be the control used for fetching EmployeeId . And what properties I need to take care of in Property window.

I want to understand how this filter exactly works.

Thanks in advance.
May 14 '15 #6
Seth Schrock
2,965 Expert 2GB
We need to see what was outputted to the immediate window in order to solve the filter problem.

A common method to store the EmployeeID for who is logged in is called Temporary Variable or TempVars.
Expand|Select|Wrap|Line Numbers
  1. TempVars.Add "EmployeeID", ID_Value
You would do this when the database first opens. Then you would modify the report criteria to call the TempVars.
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "EmployeeID = " & TempVars("EmployeeID")
May 14 '15 #7
jforbes
1,107 Expert 1GB
I'm also curious if the Report shows all records when opened from the Navigation Bar. If no records are shown when the Report is opened without a Filter, then the Filter would not be the problem.
May 14 '15 #8
Hi Seth,

Let me tell you one thing. I am using label to store current user. when I debug the line below, I get correct user Id in Immediate window. Also, report was not showing any data.
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "EmployeeId = " & txtUserID   ' where as txtUserID is storing the current user id.
  2.  

But when I used TempVar error was coming as in "Syntax error 3075"

Also the report was including all users data.

Please guide.
May 15 '15 #9
Also, one more confusion I am having is; Now when m opening the report the instead of employee id , "ID" is displayed! say if Employeeid is 111111 then it is fetching ID(ex: 34) of that row

When earlier I was using the query in (Row Source) , report was atleast displaying EmployeeId. what could be the reason for it?
May 15 '15 #10
Seth Schrock
2,965 Expert 2GB
So you are saying that if you run the report on its own, all the records get returned, but if you use your button (that has the filter) then no records get returned?

Can you please copy and paste what was in the immediate window? I would like to see what the result is as this is what isn't working.
May 15 '15 #11
Hi Seth,

Aditi here. due to some reasons I lost access to my last account temporarily. Leave that part. I need urgent fix to this issue. so I created new account.

"So you are saying that if you run the report on its own, all the records get returned, but if you use your button (that has the filter) then no records get returned? "

No. I am not getting any data in the report.

Please find the output of immediate window.

Expand|Select|Wrap|Line Numbers
  1. Debug.Print strCriteria
  2.  
  3. EmployeeId ='111111'
  4.  
Please note: I have used Row Source to fetch EmployeeId from table.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Contacts Extended].ID
  2.    , [Contacts Extended].[EmployeeId] 
  3. FROM [Contacts Extended] 
  4. ORDER BY [Contacts Extended].[Contact Name]; "
"Contacts Extended" is a query which have all field of "AddUser" table.

Please help me out
May 19 '15 #12
Any suggestions and modifications are welcome. Please help
May 19 '15 #13
Seth Schrock
2,965 Expert 2GB
In your first post, you state that EmployeeID is numeric. Please verify that if you go into design view for this table, that the data type is Number and not Text. The reason that I ask this is that your strCriteria has single quotes around the number. This will only work if the EmployeeID data type is text. If it is Number, then you can't have the single quotes around it. This could be the reason that your query isn't returning any records.
May 19 '15 #14
I confirmed it seth.
It is Numeric.
May 19 '15 #15
Seth Schrock
2,965 Expert 2GB
Then you need to remove the single quotes from around the EmployeeID as this will cause it to fail.
May 19 '15 #16
Hi seth,

sorry for confusing you. the output of immediate window is:

EmployeeId =100001

which is correct.

But now I am getting Runtime-error=2501.

"The OpenReport action was cancelled"

on line.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="IndividualTask", View:=acViewPreview, WhereCondition:=strCriteria
  2.  
May 19 '15 #17
Seth Schrock
2,965 Expert 2GB
Do you get this error only when opening the report by clicking the button, or also if you try to open it from the navigation pane?
May 20 '15 #18
No. The error occurs only when I click command button. While when I try to open through navigation pane. I displays the report but blank.

In both the case the report is blank.
May 20 '15 #19
Please find the series of error occurs when I open the report via command button.

1) Dialog occurs stating:
The section width is greater than the page width , and there are no items in the additional space, so some pages may be blank.
For example, the report width may be wider then the page width.

when I click "OK" button.

Run time Error 2501 is displayed on the same line.

(in immediate window)
Expand|Select|Wrap|Line Numbers
  1. EmployeeId=111111
  2.  
When I click on "Cancel" button in dialog
Blank report is displayed.
May 20 '15 #20
Seth Schrock
2,965 Expert 2GB
Try putting a break point at the first line of code that executes when you click the button and then step through the code. This will help you find what line of code is causing the report to cancel the opening process.
May 20 '15 #21
Hi Seth,

I tried doing that , same thing. The problem is in line:
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenReport ReportName:="IndividualTask", View:=acNormal, WhereCondition:=strCriteria
  2.  
Also, does any code results in report print?
May 20 '15 #22
Seth Schrock
2,965 Expert 2GB
acNormal view does just print the report to the default printer without displaying it.

Is there any code that runs when the report opens? Like in the On_Load or On_Open events?
May 20 '15 #23
Ok. My mistake uptil now I was using acViewPreview instead of that.
Just to see if it helps.

With Preview also it shows same error :(
May 20 '15 #24
Please help to get this thing work
May 20 '15 #25
Seth Schrock
2,965 Expert 2GB
Is there any code that runs when the report opens? Like in the On_Load or On_Open events?
May 20 '15 #26
No code is there.

Ok can you guide how to fetch data using query?

the whole process.

If this report is having problem, I will fetch the data using form and query. but the question is will it fetch current user?
May 21 '15 #27
Actually I tried fetching data using query. I used it to fetch based on the date. Which is working fine. But when I tried it using Textbox(EmployeeId) , again blank datasheet came.

Also,I tried using combobox, but no success.

I can share my code where I used combobox.

Like [Forms]![Form3]![EmpID]

where form3 is the form where combobox and command button is. And EmpID is the name of combobox.
May 21 '15 #28
I really want this thing to work ASAP.

All suggestions are welcome
May 21 '15 #29
jforbes
1,107 Expert 1GB
What concerns me most right now is:
No. The error occurs only when I click command button. While when I try to open through navigation pane. I displays the report but blank.

In both the case the report is blank.
If your report is blank when opened through the Navigation Pane, most likely the report is going to be blank no matter how it is opened.

List of questions:
  1. So how did this report get created?
  2. Did you create it?
  3. What is the RecordSource of the Report? Is it a Table or a Query, or a Query with a where clause?
  4. Was there something special done when it was created? Like changing the RecordSource in code.
  5. Is there any code in your Report?

Getting the report to open and show data from the Nav Pane is probably the first step to getting your Report to work.
May 21 '15 #30
jforbes
1,107 Expert 1GB
Also after seeing your other thread, http://bytes.com/topic/access/answer...mbobox-textbox it makes me think that the query you are using as the basis for your report has a where clause that refers to a Textbox on a Form.

There are two common ways to narrow down the contents of a Report in Access:
  1. Base the Report on a Query that has a where clause that either has a parameter in it or an expression that refers to Control on a Form.
  2. Filter a Report while opening with the DoCmd.OpenReport
These are typically mutually exclusive and only one way should be used at a time. So basing the Report on a Query with a Where Clause with a Parameter/Epression and then opening the Report with a Filter (Where Condition) will, if your not very careful, give some seemingly random results.
May 21 '15 #31
Hi jforbes,

Thanks for your response.
Currently I have used combobox to solve my problem. And it is working fine. It is displaying the result in form.

I thought of using reports to do so. But was unsuccessful in that . I tried so many things but still it was not showing any data.

anyways, I am happy atleast what I wanted is happening in datasheet view.

You people are good.

I appreciate "Seth" a lot. You are great my friend you stood with me till now. I was feeling that atleast I will get reply to my queries which I very well did.

Thanks a lot Seth.:)

thanks jforbes. :)
May 21 '15 #32

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
16
by: radio1 | last post by:
---Report the current filtered records from a Form (in an ADP project)--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. ...
5
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the...
94
by: mlcampeau | last post by:
I have a report (JobVacanciesOnly) that has a subreport (JobVacanciesOnlySR) that are based on two separate queries. MY - JobVacancyJobs SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum,...
6
by: pouj | last post by:
what i want to do is basically have form where my selection in the combox make the diffrence with what the form reports. this is what the underlying informaion is.... software is access 2007 i...
13
by: masteraccess2008 | last post by:
I create in Access report based on user defined function(UDF) in SQL Server which returns table. CREATE FUNCTION MyFunc_VP (@VP varchar(12)) RETURNS TABLE AS RETURN (SELECT...... In Access,...
0
by: munkee | last post by:
Hi all, This would normally be quite simple however for some reason I can not getting working. My code to open my report filtered to a primary key is as follows: Case "Full record"...
1
by: Neobeowulf | last post by:
Team, I'm totally stumped on this one. I'm trying to create a button called "Run Report" that opens a report based off a selection made in a combo box then filtered by a column in the report...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.