Results 1 to 3 of 3
  1. #1
    sabre1 is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    22

    Creating a report from a form

    I am trying to create a report from a form where a user can decide which fields they would like to show in a report. The form would contain check boxes and list boxes so the user can also filter on fields and for instance only show the active accounts instead of all accounts. Can someone please point me in the right direction of how i can do this.


    Thanks.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you know, you might need to create the query through code with this kind of complexity. something like:
    Code:
    button on_click()
    
    on error resume next
    
    currentdb.querydefs.delete "myquery"
    
    dim qry as dao.querydef
    dim activeaccts as boolean
    dim sql as string
    dim temp as string
    dim i as integer
    
    temp = ""
    
    if me.activeaccountsCbox = -1 then
       activeaccts = true
    end if
    
       for i = 0 to me.ListBoxFields.listcount - 1
          if me.listboxfields.column(0, i).selected then
             temp = temp & me.listboxfields.column(0,i) & ","
          end if
       next i
                  temp = iif(temp = "", "", left(temp, len(temp) - 1))
    
    sql = "SELECT "
    sql = sql & iif(temp = "", "* ", temp) & " "
    sql = sql & "FROM table "
    sql = sql & iif(activeaccts = true, "WHERE [activeaccounts] = -1", "")
    sql = trim(sql)
    
    currentdb.createquerydef("myquery", sql)
    
    refreshdatabasewindow
    
    docmd.openreport "myreport", acViewPreview
    that returns all records if no fields are selected. If the report is based on that query, it can be dynamic with code similar to that.

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    generically speaking a Report object has a record source - and the controls on the Report are fixed. One typically is managing the record set within the record source - - - not the Controls on the Report.

    You can toggle on/off visibility of controls on the Report. But you can't really make new controls appear. So in terms "decide which fields they would like to show in the report"...you would toggle on/off visibility of controls based on the form selection via the visibible property - - and trigger it in the OnFormat Event of the section that the controls appear.

    Hope this helps.

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

Similar Threads

  1. creating report
    By Balen in forum Reports
    Replies: 1
    Last Post: 08-12-2010, 06:45 PM
  2. Creating a report
    By nebuk89 in forum Reports
    Replies: 3
    Last Post: 07-01-2010, 06:49 AM
  3. Replies: 3
    Last Post: 01-14-2010, 08:32 AM
  4. Help with creating a Report..
    By TylerZ07 in forum Reports
    Replies: 2
    Last Post: 12-11-2009, 07:51 AM
  5. Replies: 5
    Last Post: 07-26-2009, 12:13 PM

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