Results 1 to 10 of 10
  1. #1
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55

    Combo Box for Report

    access 2007,

    I have a report that is using a query as the control source. This report is based on many Account Names. I have a command button that when clicked will preview the report for printing. This works fine.

    What I would like to do is have the ability to pick from probably a combo box just one Account Name in need be and print that selection rather than printing the whole report.

    Not quite sure how to set this up. Do I need to create the combo box on my form and have the control source set to the query?

    And how do I get the report to accept the selected account name?

    Thanks to all!


    Bruce D.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I'd go one of two ways. If you will always pick a name, I'd use this:

    BaldyWeb wherecondition

    If you want to be able to leave the combo blank to get everybody, I'd do this:

    http://access.mvps.org/access/queries/qry0001.htm

    Now that I think about it, a third option would be choosing multiple names:

    http://www.baldyweb.com/multiselect.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    Paul,

    Thanks, I think I am going to try and use the 3rd option. This should be helpful in getting me started.

    Thanks!!
    Bruce

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help Bruce!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    Can anyone figure out what I might be doing wrong? When I click on my button to run the report I am receiving:

    'Syntax error in query expression 'AccountName IN('Agents Choice)'.

    My table name is Export_Billing
    The unbound List Box is called lstAccountName with the row source of:

    SELECT DISTINCT Export_Billing.AccountName FROM Export_Billing;
    My Event Procedure for the button is:

    Private Sub cmdOpenReport_Click()
    On Error GoTo Err_cmdOpenReport_Click
    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant
    'make sure a selection has been made
    If Me.lstAccountName.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 Customer"
    Exit Sub
    End If
    'add selected values to string
    Set ctl = Me.lstAccountName
    For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","
    'Use this line if your value is text
    strWhere = strWhere & "'" & ctl.ItemData(varItem) & "'"
    Next varItem

    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    DoCmd.OpenReport "Copy Of Departmental Data Report", acPreview, , "AccountName IN(" & strWhere & ")"
    Exit_cmdOpenReport_Click:
    Exit Sub
    Err_cmdOpenReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenReport_Click
    End Sub

    I am thinking somewhere in the above might be where the syntax is wrong.

    Any ideas?
    Thanks!!!

  6. #6
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    I just found out I was missing the , in the ctl.ItemData(varItem) & "',"

    It is working now but I thought this would let me select more than entry in the List box? Anyway I can live with this.

    Thanks.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The code should let you choose multiple items. Make sure the multiselect property of the listbox is set to allow it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    Paul,

    Yes, that was it!!

    Bruce D

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem Bruce!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    PeteDC is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    1

    How would you preivew the Report?

    Quote Originally Posted by pbaldy View Post
    I'd go one of two ways. If you will always pick a name, I'd use this:

    BaldyWeb wherecondition

    If you want to be able to leave the combo blank to get everybody, I'd do this:

    http://access.mvps.org/access/queries/qry0001.htm

    Now that I think about it, a third option would be choosing multiple names:

    http://www.baldyweb.com/multiselect.htm
    I used the first option, but it went to the printer without first previewing the report. How would I create a "Preview Button" so I can look at the report prior to printing?

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

Similar Threads

  1. Choose Parameter combo box for report
    By RobRay in forum Reports
    Replies: 10
    Last Post: 08-10-2011, 02:48 PM
  2. Replies: 3
    Last Post: 05-05-2011, 09:33 AM
  3. using unbound combo box to filter report
    By jlclark4 in forum Reports
    Replies: 1
    Last Post: 01-25-2011, 04:12 PM
  4. combo box for sub report
    By combine21 in forum Reports
    Replies: 1
    Last Post: 09-29-2010, 09:48 PM
  5. Combo box to select report to Print
    By usmcgrunt in forum Reports
    Replies: 4
    Last Post: 09-17-2010, 06:44 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