Results 1 to 3 of 3
  1. #1
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32

    Dynamic report, populated by combobox

    Hi guys, i'm kinda noob in the report field and i wanted to ask if it's possible to make a report that populates its fields with tables chosen by a combobox.


    Example: i have a form with a combobox where i can chose from a dozen table names, then a button opens the report. Now, all those tables have, among others, 3 identical fields (same name, same property. Yes, it's not normalized. No, i can't change it ), so it would be perfect if there was a way (VBA i guess) to make it populate these 3 fields in the report (that only has those 3 columns) with data coming from the table selected in the combobox, so i don't have to make dozens of reports almost identical, but only one....
    Thanks, hoping i have explained myself

  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,770
    It is possible. One way is to set the report RecordSource property. I do this for one report.

    Code behind the report:

    Private Sub Report_Open(Cancel As Integer)
    'report is called by SampleManagement and zPre2009SamplesView forms to print list of samples
    'set RecordSource to pull data from appropriate tables
    Me.RecordSource = Nz(Me.OpenArgs, Me.RecordSource)
    End Sub

    Code that opens the report from two locations - it passes the SQL string for the report RecordSource in the OpenArgs argument:

    DoCmd.OpenReport "SampleList", IIf(booView = True, acViewPreview, acViewNormal), , Replace(Me.Filter, "zPre2009SamplesView", "SampleList"), , Me.RecordSource

    DoCmd.OpenReport "SampleList", acViewPreview, , Me.ctrSampleList.Form.Filter, , Me.ctrSampleList.Form.RecordSource


    Another approach might be a UNION query of the dozen tables and use the UNION as report RecordSource and apply filter to report.

    SELECT 1 As Source, field1, field2, field3 FROM Table1
    UN ION SELECT 2, field1, field2, field3 FROM Table2
    ...;
    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
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Thanks, made it work!

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

Similar Threads

  1. Replies: 1
    Last Post: 12-04-2013, 09:21 AM
  2. Replies: 11
    Last Post: 11-25-2013, 01:46 PM
  3. Dynamic ComboBox Not in List Code Error
    By quicova in forum Programming
    Replies: 7
    Last Post: 09-19-2013, 08:10 AM
  4. Replies: 9
    Last Post: 01-17-2013, 09:08 PM
  5. Replies: 5
    Last Post: 07-29-2011, 03:07 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