Results 1 to 10 of 10
  1. #1
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29

    Ref a tab in form for Report

    Hello,



    I have Form with a tabctrl and list on the tabctrl that are being populated using SQL statement. I want to print what is on the tabctrl list to a report. I added a list on the form and referenced forms!frm_city!tabctrl.list20 but it's not working. Please help.

  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
    The tab control is not part of the reference. Leave it out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    I did.. Still not working. Here is what I have [Forms]![frm_city]!
    [list20]

    What should it be?

  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
    That looks okay:

    Forms Refer to Form and Subform properties and controls

    Is the listbox multi-select? If so, code would be required, like:

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

  5. #5
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    Here is my code and its not working

    Private Sub cmdOpenReport_Click()
    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant

    'make sure a selection has been made
    If Me.lstzipcode.ItemsSelected.Count = 0 Then
    MsgBox " Must select at least 1 zipcode"
    Exit Sub
    End If

    'add selected values to string
    Set ctl = Me.lstzipcode
    For Each varItem In ctl.ItemsSelected
    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 "Zipcode", acPreview, , "City_Zipcode IN(" & strWhere & ")"

    Exit_cmdOpenReport_Click:
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What does "not working" mean exactly? Is the field text? If so, you need the other line from the link.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    It a list field the gets the information from a table. When i highlight the number and tell it openreport it give me a vba error on 3075 " Syntax error( missing operator) in query expression 'City_zipcode IN (32455)'.

    Thank you so much for your help

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That looks okay for a numeric data type. Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    yagerlegi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2014
    Posts
    29
    I think I got.. it was missing the single and double quote in the middle... strWhere = strWhere & "'" & ctl.ItemData(varItem) & "',"

    Thank you.. Now I need to count(city) the unique site header on report.. Thank you again

  10. #10
    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. That's why I asked about the data type. The extra quotes are required if the data type is text.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2014, 05:15 AM
  2. Replies: 3
    Last Post: 03-11-2013, 05:11 PM
  3. Replies: 1
    Last Post: 06-26-2012, 08:19 PM
  4. Replies: 1
    Last Post: 07-15-2011, 10:59 PM
  5. Replies: 4
    Last Post: 12-13-2010, 05:33 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