Results 1 to 15 of 15
  1. #1
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52

    Question Button to Generate Report from Form

    I'm fairly new to this, so please, bear with me. I'm currently working on a large project. Part of what I'm using stores recipes. I have three tables, one that stores recipes, another that stores items, and the last one joins the recipes with specific items.



    I have managed to create a Report that enables me to view them continuously, and a Form that does as well (for easy entering), but I am having trouble figuring out how to have a recipe displayed in Form view and (with a button) view the recipe in the Report (in record view - so only the one recipe is showing).

  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
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    I suppose that could work, I was hoping to open it in report view (if it's possible).

    So, I suppose the first question that really needs to be answered is if it's possible to view one record at a time in report view as it is in form view.

    Like this - but I really only want one recipe to be viewed at a time in report view.
    Attachment 19548

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Can open report filtered to single record using the code method from Paul's article. Or can configure report to show each recipe record on a separate page in print preview.

    Can open in report view or print preview. This is possible with argument of OpenReport. Should get familiar with the arguments of OpenForm and OpenReport methods. https://msdn.microsoft.com/en-us/lib...ffice.15).aspx
    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.

  5. #5
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    You're right, June7, I don't know how I missed that!

    I'm having a bit of trouble with the SQL syntax. As I understand it, when I click on the item, in the instance below, a text field, it should open my report filtering on the specified record. But what happens is a dialogue box pops up asking for me to enter 'txtRecipeName'. If what I type matches something, ALL my recipes are displayed. If it doesn't match anything, then a blank record is displayed (both in report view, though).

    Also, please see the attached database. Thanks for all your help! I really appreciate it.

    Code:
    Private Sub txtRecipeName_Click()
        Dim Name As String
        Name = Me.txtRecipeName
        DoCmd.OpenReport "rptRecipeList", acViewReport, , "txtRecipeName = '" & Name & "'"
    End Sub
    Attachment 19555

  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,521
    txtRecipeName needs to be the name of a field in the report's source. Name needs to be the name of the textbox on the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    Yes, that is the case.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So did you fix the code? Is issue resolved?
    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.

  9. #9
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    I already have it written the way he had specified. txtRecipeName (is the field on the Report) Name (is retrieved from the Form).

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Name is a reserved word and should not be used as name for anything. Use something like: tbxName. Then in VBA code: Me.tbxName
    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.

  11. #11
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    I have changed the variable name and am still encountering the same issue.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Variable name? I thought you were referencing a textbox control on form? The suggestions indicate to reference control name.

    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.

  13. #13
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Okay, here is what I see.

    The field name is RecipeName.

    The textbox name is txtRecipeName.

    Therefore, the correct code is:
    DoCmd.OpenReport "rptRecipeList", acViewReport, , "RecipeName = '" & Me.txtRecipeName & "'"

    However, you have code behind rptRecipeBook. This won't work if the report is opened in Preview mode. Why isn't code behind form?
    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.

  15. #15
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    I was actually just playing with it to get it to work! lol I knew it had to be something silly and simple like that. D'oh!

    Thank you both for your help and your patience. This is a big project for me to take on, so there might be more questions. Thanks again!

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

Similar Threads

  1. Replies: 2
    Last Post: 12-15-2014, 04:53 AM
  2. Replies: 3
    Last Post: 10-20-2014, 03:25 PM
  3. Generate button in report ONLY IF link exists
    By rhewitt in forum Programming
    Replies: 7
    Last Post: 10-25-2012, 01:38 PM
  4. Replies: 2
    Last Post: 03-06-2012, 07:20 PM
  5. Replies: 2
    Last Post: 04-12-2011, 08:33 PM

Tags for this Thread

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