Results 1 to 8 of 8
  1. #1
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92

    OpenReport based on list box result

    Hello,

    I am trying to setup a button that will open a report on click. The catch is that the report name is coming from a query result that is populated into a list box. The way it works the list box will never have more than one result so by default it will always house the name of the report appropriate to a chosen client. I would like to do it this way so that I don't have to clutter up the from with extra buttons all pointing to specific reports.

    I found some refrences to this in this forum, including the example listed below, but I have been unsucessful in making work so I assume that I am entering wrong, entering it the wrong place or maybe the code is incomplete. Unforntunately I am a complete novice to Access VBA so I am still learning how it all works together.


    List box name is BillingFormat
    The first of 5 reports is named Standard Billing

    So in the form I enter the client number and BillingFormat is auto populated with Standard Billing

    I tied the button to this code: DoCmd.OpenReport Me.BillingFormat, acPreview

    The results I was looking for was for the report named Standard Billing would open. The first way I set it up nothing happened not even any errors. The other way threw an error stating it did not recognize DoCmd as a valid function.



    Can someone tell what I am doing wrong? Am I even on the right track?

    Thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is the SQL for the list box?
    What is the bound column number?

  3. #3
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92
    Okay, my Access ignorance is showing. I don't see a way to veiw the SQL for the list box. Did you mean the SQL of the query the list box is pulling from? The data is in the 10th column of the query so if I understand correctly that the columns start at zero then that would be column 9.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe you can start by pasting the rowsource of the listbox here.

  5. #5
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92
    SELECT [GS Secondary Details].[Billing Format] FROM [GS Secondary Details] ORDER BY [Billing Format];

  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,626
    The RowSource and the OpenReport both look correct.

    Is a form/subform arrangement involved? Bound or unbound forms? If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92
    I don't understand why it made a difference but I made what I would think would be a small change and now it is working. I copied then deleted the code, changed the name and caption of the button then pasted the code back in and now it is working perfectly. I am not sure why the name or caption would make any difference but something about it did.


    Thanks

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    It happens that way sometimes. If you can imagine numbers that count each line of code in the VBA editor..... You don't want to drag around a sub routine e to a different line number.

    The code in the middle of a procedure is one thing. But Access does not like it when you move the first or last line of a routine.

    There are other ways to goof things up too

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

Similar Threads

  1. Replies: 9
    Last Post: 05-08-2013, 02:37 PM
  2. Change field color based on result
    By dniezby in forum Programming
    Replies: 1
    Last Post: 05-01-2013, 09:43 PM
  3. Return result based on %
    By Guitarzan in forum Access
    Replies: 1
    Last Post: 08-08-2012, 09:18 AM
  4. Enter result according to drop down list
    By frosty in forum Access
    Replies: 3
    Last Post: 10-12-2011, 07:38 AM
  5. Replies: 3
    Last Post: 11-19-2010, 01:48 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