Results 1 to 14 of 14
  1. #1
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Buttons in reports to sort

    Hey there, I have a report that I was wondering if its possible to make certain parts of it selectable to narrow down results. Ive attached a picture of the report. As you can see I would want it so they can select the employees name and it will filter all dates and info only that employee has worked. The same goes for the date, select the date and show all employees who have worked on that date and what they have done. Also want it to work for the modular unit serial number, select the number and show the employee and date that they worked on just that number.

    Is this easier or more complicated then it seems? do I need to make more reports or is it just an on click procedure? my vba skills and overall access skill level is beginner, so any extra detail is appreciated. Thanks!


    Click image for larger version. 

Name:	report1.PNG 
Views:	17 
Size:	25.7 KB 
ID:	22587

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So you want dynamic filter, not sort?

    I would use a form for user to input criteria then VBA to build filter string and apply to report when it is opened.

    Review http://www.allenbrowne.com/ser-62.html

    The code could be modified with:

    DoCmd.OpenReport "reportname", , , strWHERE
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    okay thanks, so to clarify there is no way to make those fields selectable and use those to sort before changing to print preview?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What you describe is filtering, not sorting. I open report to Print Preview.

    DoCmd.OpenReport "reportname", , acViewPreview, strWHERE

    Sorting can be programmatically dynamic, just a little trickier, especially if report has Sorting & Grouping settings.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I have never tried it before so I gave it go. As June mentioned, what you desire is not Sorting. What you are referring to is being able to change the Report's Rcordsource or Filter property. If you have grouping and sorting, you can access a group via its index. here is some example code for sorting (you are not asking about sorting).
    Code:
    If Me.GroupLevel(0).SortOrder = False Then
        Me.GroupLevel(0).SortOrder = True
    Else
        Me.GroupLevel(0).SortOrder = False
    End If
    You could place code like this within a textbox control's DblClick event, for example. You could use differnet code, too. You could build code to affect the Filter property of the report. Here is an example. Also, you would probably want a command button in the header to remove the filter.
    Code:
    Dim strFilter As String
    strFilter = ""
    Me.FilterOn = False
    Me.Filter = strFilter
    If Not IsNull(Me.NameOfControl.Value) Then
        strFilter = "[NameOfField] = '" & Me.NameOfControl.Value & "'"
        Me.Filter = strFilter
        Me.FilterOn = True
    End If

  6. #6
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    so what am I putting in the strFilter = "" , if I input that code and change my control and field name. and run it and click. it just makes a blank record that has no values, see below:

    Click image for larger version. 

Name:	report2.PNG 
Views:	16 
Size:	4.3 KB 
ID:	22594Click image for larger version. 

Name:	report3.PNG 
Views:	16 
Size:	7.1 KB 
ID:	22593

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The referenced link is code to set filter of a form. I already described in post 2 how to modify to apply filter to report (also described by Allen in the tutorial).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    One thing you might try is to use a msgbox to understand what filter is being applied. Also, I notice that the DblClick event you are using is for a control different than ModUnitSerialNum. Perhaps ModUnitSerialNum does not have a value. Maybe place your code in the ModUnitSerialNum DblClick event.

    Here is an example you can use for displaying what the filter criteria is that is being applied.
    Code:
    Dim strFilter As String
    strFilter = ""
    Me.FilterOn = False
    Me.Filter = strFilter
    If Not IsNull(Me.NameOfControl.Value) Then
        strFilter = "[NameOfField] = '" & Me.NameOfControl.Value & "'"
        Me.Filter = strFilter
        msgbox strFilter
        Me.FilterOn = True
    End If

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    The referenced link is code to set filter of a form. I already described in post 2 how to modify to apply filter to report (also described by Allen in the tutorial).
    It seems redekopp desires the user interact with a report in Report View. The OP also requests an explanation how the user might interact with a control on a report to change its appearance. I am not sure I would use Docmd when you can access the Filter property directly.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Okay, I've never set up reports for ReportView and dynamic interaction.

    ModUnitSerialNum a text field?

    Hoping there is no lookups set in table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    Okay, I've never set up reports for ReportView and dynamic interaction....
    Me either. And yah, not sure if they need text or numeric. I took a gamble. There is the link to Roger's for reference, anyway.

  12. #12
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    thanks for your reponses guys, I took a different approach and made a form with tempvars to filter the report. Im having an issue doing a date search though.

    My data is only a shift date, but obviously I need to search from a start date to an end date if I wanted everything in between. I know I made the form right and the tempvars correctly. Its doing the criteria in my qry im not sure about. I did it doing a criteria and a "or" such as the screenshot attached. It wont filter properly though. it still gives me dates before and after what I put into my tempvars. Do I need a different statement in my "criteria" only?

    Thanks.

    Click image for larger version. 

Name:	tempvars.PNG 
Views:	13 
Size:	2.6 KB 
ID:	22617

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You don't want OR, should be AND.

    Try:

    BETWEEN [TempVars]![tmpStartDate] AND [TempVars]![tmpEndDate]
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    edit; I got it to work, thanks for your help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to sort using radio buttons?
    By PoorCadaver in forum Programming
    Replies: 33
    Last Post: 04-18-2013, 06:44 AM
  2. Hiding Command Buttons in Reports?
    By Rosier75 in forum Reports
    Replies: 8
    Last Post: 01-14-2013, 01:34 PM
  3. GUI buttons to show reports?
    By brownk in forum Access
    Replies: 2
    Last Post: 05-15-2012, 08:59 AM
  4. Replies: 1
    Last Post: 02-27-2012, 06:22 PM
  5. Creating Sort Buttons in a Header in a list view
    By marttaaayyy!! in forum Programming
    Replies: 4
    Last Post: 03-29-2010, 11:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums