Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9

    Reports - Access 2007

    Hello, I am pretty new to Access. I have used databases before and even created some very basic ones many years ago, but new to relational databases. I have been trying to learn the basic concepts of Access for the following task:

    • I have an Access Database to store information about a project which consists in the Volunteers details. These are the fields in the tblVolunteers:

    Role, Volunteer Name, Address, Telephone, Mobile, Email, Borough, Age, Gender, Sexual Orientation, Employment, Disability, Religion, Ethnic Background, Language, Previous Volunteering, Aspirations, Worker Name and 8 Actions.

    I would produce an Access Report based on user selection. The user selects the field(s) that they would like to report to. Is this possible?

    Thanks in advance


    AlfBar

  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,632
    Not without a lot of VBA code.

    Build various reports and offer users choice to run.

    Sexual orientation is relevant data - really?
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Yes. You 1st build a QUERY to get the info you want.
    Then make a report off this, and produce the sort order, sums, etc.

    For user selections...build a FORM with the text boxes or combo boxes for users to select.
    Then the query in the report would read these.

    But some VB may be needed...on the REPORT button click event, you would have to determine the filters needed...
    If you need complex form filters THEN make a query from it, do this:

    Code:
    Public Sub btnReport_Click()
    Dim sSql As String, sWhere As String
    Dim qdf As querydef
    Const kQRY = "qsFormFilter"    'here is the query we use ...in the report too
    
        'the query is built depending on the various filters the user picks...
    If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
    If Not IsNull(txtName) Then sWhere = sWhere & " and [Name]='" & txtName & "'"
    If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value
        'remove 1st And
    sWhere = Mid(sWhere, 4)
    Set qdf = currentdb.querydefs(kQRY)
    qdf.Sql = "SELECT * FROM tblCompany"
    If sWhere <> "" Then qdf.Sql = qdf.Sql & " WHERE " & sWhere
    qdf.Close
    
    'open the query or report here!
    'DOCMD.openquery kQRY
    'DOCMD.OPENREPORT "rMyReport"
    End Sub

  4. #4
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9

    Reports - Accesss 2007

    Quote Originally Posted by June7 View Post
    Not without a lot of VBA code.

    Build various reports and offer users choice to run.

    Sexual orientation is relevant data - really?

    Thank you for the quick reply. I am going to try it and let you know the outcome.

    Cheers
    AlfBar

  5. #5
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9

    Reports - Access 2007

    Quote Originally Posted by AlfBar View Post
    Thank you for the quick reply. I am going to try it and let you know the outcome.

    Cheers
    AlfBar
    Hello,

    I tried the code, but an error occour - Run Time - Error 424 - Object Required

    Here is the code:
    Private Sub btnReport_Click()
    Dim sSql As String, sWhere As String
    Dim qdf As QueryDef
    Const kQRY = "qsFormFilter" 'here is the query we use ...in the report too
    'the query is built depending on the various filters the user picks...
    If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
    If Not IsNull(txtName) Then sWhere = sWhere & " and [Name]='" & txtName & "'"
    If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value
    'remove 1st And
    sWhere = Mid(sWhere, 4)
    Set qdf = CurrentDb.QueryDefs(kQRY)
    qdf.SQL = "SELECT * FROM tblCompany"

    If sWhere <> "" Then qdf.SQL = qdf.SQL & " WHERE " & sWhere
    qdf.Close
    'open the query or report here!
    'DoCmd.OpenQuery kQRY
    'DOCMD.OPENREPORT "rMyReport"

    End Sub

    ************
    The red bit it is where the error occours.

    Thanks
    AlfBar

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Not sure why that line errors. Is Contact a yes/no type field and chkContact is a checkbox? Do you want to filter by Contact only if the checkbox is true? Try:

    If chkContact = True Then sWhere = sWhere & " AND [Contact]=" & chkContact

    Suggest removing the code referencing QueryDef. Don't open query. Don't modify query def. Just apply filter string to report. Uncomment the OpenReport line and use your actual report name.

    DoCmd.OpenReport "actual report name here", , , sWhere
    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.

  7. #7
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9
    Quote Originally Posted by AlfBar View Post
    Thank you for the quick reply. I am going to try it and let you know the outcome.

    Cheers
    AlfBar
    Hi ranman56,

    Thank you for the code that you provided. I have some questions: what is cboState, txtName and chkContact?

    The does not work. It comes up with an error Run -Time Error 424 - Object Required in the following line:
    If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value

    Thank you but I need some help
    AlfBar

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Those are names of combobox, textbox, checkbox - used as examples.

    You need to modify the code to use your field and control names. Adapt.

    Did you review post 6?
    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.

  9. #9
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9
    Quote Originally Posted by June7 View Post
    Those are names of combobox, textbox, checkbox - used as examples.

    You need to modify the code to use your field and control names. Adapt.

    Did you review post 6?
    Hi June7,

    Thanks for your reply. Yes I reviewed post 6 and I took it in consideration.

    AlfBar

  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,632
    So did you modify code as appropriate for your db?
    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
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9
    Quote Originally Posted by June7 View Post
    So did you modify code as appropriate for your db?
    Hi June7,

    I adapted the code to match my database. Here is the code:
    Public Sub btnReport_Click()
    Dim sSql As String, sWhere As String
    Dim qdf As QueryDef
    Const kQRY = "qsFormFilter" 'here is the query we use ...in the report too
    'the query is built depending on the various filters the user picks...

    If Not IsNull(Check13) Then sWhere = sWhere & " and [Role]=" & Check13.Value
    If Not IsNull(Check11) Then sWhere = sWhere & " and [VolName]=" & Check11.Value
    If Not IsNull(Check9) Then sWhere = sWhere & " and [VolAddress]=" & Check9.Value
    'If Not IsNull(Check7) Then sWhere = sWhere & " and [Telephone]=" & Check7.Value
    If Not IsNull(Check19) Then sWhere = sWhere & " and [VolMobile]=" & Check19.Value
    If Not IsNull(Check15) Then sWhere = sWhere & " and [VolMail]=" & Check15.Value
    If Not IsNull(Check21) Then sWhere = sWhere & " and [VolBorough]=" & Check21.Value
    If Not IsNull(Check23) Then sWhere = sWhere & " and [VolAge]=" & Check23.Value
    If Not IsNull(Check25) Then sWhere = sWhere & " and [VolGender]=" & Check25.Value
    If Not IsNull(Check27) Then sWhere = sWhere & " and [VolSexsualOrientation]=" & Check27.Value
    If Not IsNull(Check29) Then sWhere = sWhere & " and [VolEmployment]=" & Check29.Value
    If Not IsNull(Check31) Then sWhere = sWhere & " and [VolDisability]=" & Check31.Value
    If Not IsNull(Check33) Then sWhere = sWhere & " and [VolReligion]=" & Check33.Value
    If Not IsNull(Check35) Then sWhere = sWhere & " and [VolEthnicBackground]=" & Check35.Value
    If Not IsNull(Check37) Then sWhere = sWhere & " and [VolLanguage]=" & Check37.Value
    If Not IsNull(Check39) Then sWhere = sWhere & " and [VolPeviousVolunteering]=" & Check39.Value
    If Not IsNull(Check43) Then sWhere = sWhere & " and [VolAspirations]=" & Check43.Value
    If Not IsNull(Check45) Then sWhere = sWhere & " and [Workername]=" & Check45.Value
    If Not IsNull(Check47) Then sWhere = sWhere & " and [VolActions]=" & Check47.Value
    'remove 1st And
    sWhere = Mid(sWhere, 4)
    Set qdf = CurrentDb.QueryDefs(kQRY)
    qdf.SQL = "SELECT * FROM tblVolunteer"
    If sWhere <> "" Then qdf.SQL = qdf.SQL & " WHERE " & sWhere
    qdf.Close
    'open the query or report here!
    'DoCmd.OpenQuery kQRY
    DoCmd.OpenReport "Report1"
    End Sub

    I have a Run-Time Error 3265 - Item not found in this collection.
    The line that is the culprit is:

    Set qdf = CurrentDb.QueryDefs(kQRY)

    The values between the square brackets [], are the names of the fields in tblVolunteer?

    Thanks in advance
    AlfBar

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    See third line of post 6.

    The controls are all checkboxes? The fields are what data type? Why would you apply a True/False parameter to an Address, Telephone, Gender, etc. field?
    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.

  13. #13
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9
    Yes, all controls are checkboxes. They are presented to users for them to choose which fields they want to include in the report. The fields are all the Text data type.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Okay, I was confused. I thought you were building filter criteria string.

    But how will this work with report? The report is not dynamic as far as the textboxes and the fields they are bound to.
    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.

  15. #15
    AlfBar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Location
    United Kingdom
    Posts
    9
    Okay, let me explain.
    I have a database that records volunteers details. I want to be able to create a report, based on a query that allows the user to be able to report on fields from tblVolunteer which they would like to report.
    I presented one form to the users with checkboxes for each field to allow them to select (or not) accordingly the requirement.

    Is this possible to do it?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2007: Using new TrueType font in forms/reports.
    By superfury in forum Database Design
    Replies: 1
    Last Post: 04-19-2012, 08:11 AM
  2. 2010 and 2007 Access Queries, Forms & Reports
    By rpaldridge in forum Import/Export Data
    Replies: 3
    Last Post: 02-11-2011, 07:37 AM
  3. Replies: 0
    Last Post: 02-08-2011, 02:34 PM
  4. Access 2007 Reports Based on ID
    By tdw.mark in forum Reports
    Replies: 1
    Last Post: 08-26-2010, 10:34 AM
  5. Cannot edit reports in Access 2007
    By sconard in forum Reports
    Replies: 3
    Last Post: 12-23-2009, 08:06 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