Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86

    Report To Open Based on Comobox Selection

    I have some code that was written by someone else. I am trying to duplicate this in another database but, can't seem to get it to work. I also don't understand how this code is working as as there is no reference to the combo box in the code behind the print button. But depending on what you select in the combo box the report opens and filters on that selection. Can someone help me understand how this is working, so I can get it work as well. The following code is behind the print button. There is a separate combo box, that does not seem to have a connection to the print button. It just has a query behind it for the items to select from. Thanks!


    Public Sub BTNPrint_Project__Job__Numbers_Click()


    On Error GoTo Err_BTNPrint_Project__Job__Numbers_Click

    Dim stDocName As String
    stDocName = "RPTProject Number (Job) Book Year"
    DoCmd.OpenReport stDocName, acPreview
    Exit_BTNPrint_Project__Job__Numbers_Clic:
    Exit Sub
    Err_BTNPrint_Project__Job__Numbers_Click:
    MsgBox Err.Description
    Resume Exit_BTNPrint_Project__Job__Numbers_Clic
    Last edited by Njliven; 05-09-2013 at 10:09 AM. Reason: clarification

  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,521
    First thing I'd check is the record source of the report. It may be a parameter query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    Already check that, it is not a parameter query.

  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,521
    Second place to look is code in the open or load events of the form. If you don't find it there, can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and check the filter property of the report too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Further to Paul's comment, if the combo is involved in selecting the Report to run, then somewhere that selected value must adjust the underlying recordset, or Filter, or Openarg....
    Can you post a copy of the database -- remove anything confidential?

    Have you done a search for the combo box name in your project?

  7. #7
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    There is a filter on the report, if refereces the form and the combo box, which makes sense. But, when I put the filter on the one I am trying to create, it comes up with a box like it is looking for the data, of course if I just continue I get a blank report, if I enter the data here the report runs, but it should run without having to enter anything. It should be getting the from the combo box. I keep thinking I have some typo, but I copied and pasted the names of the form and combo box to try and avoid this error. But something is still not right, any suggestions.

  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,521
    The form is open at the time? I don't personally use that method as a rule. I either use a parameter query or this:

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The working report must have a dynamic parameter in some query involved in the RecordSource - criteria that is a reference to combobox. It's the only explanation for it to be working properly.

    I also prefer using the WHERE CONDITION argument over dyanmic query parameters.
    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.

  10. #10
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    I found the problem. It was in the form name. I had pulled the form name from the caption, which was different that the actual name of the form.
    Here is another problem I am facing with this. I went in and made an unrealted change to the report, add another field. Then when I went to run the report the filter was gone.
    I re-entered the filter and it works, but how can I prevent this from happening. Can this filter be coded in the code behind the print button. I tried to do that but, can't seem to get it work. Not sure just where it goes or how it should be stated there. Part of this problem is that the filter is more complicated than just a field. Here is the code for my filter

    left([ProjectID],2) = Right([Forms]![frm_CO_PROJ_Main]![cmb_PrintPROJYear], 2)

    It is matching the right two digits from the year in the combo box to the first 2 digits in the Project ID field.

    Thanks for all the help.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    ...so it is matching the first 2 digits of the ProjectID with the last 2 digits of the year
    Not really. It is assigning the
    Code:
    the rightmost 2 digits of the year
    to
    Code:
    the leftmost 2 digits of ProjectID
    I agree with Paul and June7, your should probably adjust the code and use a WHERE CONDITION.

    I would still recommend that you remove the embedded significance of the code and only concatenate for display.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by orange View Post
    Not really. It is assigning the
    Code:
    the rightmost 2 digits of the year
    to
    Code:
    the leftmost 2 digits of ProjectID
    I disagree; in the filter, it's filtering, no different than a filter of:

    FirstName = "Paul"

    but I agree about switching methods.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    so can someone be more specific about what I need to do in order to change methods. Does something need to exist in the code behind the actual print button? If so, can some one help me figure out how to write it so it works. I have attempted to do this, but have had no luck in getting it to work there. Thanks!

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you see the link in post 8?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    Yes, that what I tried to use as guide, but I could not seem to get the right combination to get it to work.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Open Report based on list box selection
    By BorisGomel in forum Access
    Replies: 2
    Last Post: 04-17-2013, 02:41 PM
  2. Replies: 8
    Last Post: 02-07-2013, 09:01 PM
  3. Replies: 1
    Last Post: 12-09-2012, 05:27 PM
  4. Replies: 3
    Last Post: 10-31-2011, 04:54 PM
  5. Replies: 1
    Last Post: 09-21-2011, 03:21 AM

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