Results 1 to 4 of 4
  1. #1
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86

    Open a report using a WHERE clause as criteria from a form

    Hi



    I have a form which has a button which opens an additional report using a text box on the form as criteria. This works fine when the form is opened by itself but when I open from within a navigation form it doesn't work.

    I could change the WHERE clause to lookup through the navigation form but I want the WHERE clause to work when the form is opened by itself or from within a navigation form.

    I have 3 forms as follows
    frmNavigation1
    frmNavigation2
    frmProduct - Standalone form or as a sub form to the navigation forms.

    I've used the macro builder on the button to open the report and have used the WHERE clause...
    Code:
    [product]=[Forms]![frmProduct]![product]
    I want create the WHERE clause in a way that allows the report to open correctly whichever form is opened up. How do I code this?


    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    usage:
    OpenMyRpt "rMyRpt", "[prodCode]='" & me.txtProdCode & "'"

    Code:
    sub OpenMyRpt(byval pvRpt , byval psWhere as string )
    
     docmd.openReport pvRpt  ,acViewPreview, ,psWhere
    end sub

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Ranman provides VBA code. I agree, use VBA instead of macro.

    Could use the generic sub he suggested or just in button click event:

    DoCmd.OpenReport "reportname", acViewPreview, , "[product]=" & Me![product]

    Assumes [product] is a number type.
    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.

  4. #4
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    Quote Originally Posted by June7 View Post
    Assumes [product] is a number type.
    The product is actually a string.

    I managed to get it working using a variable in already existing code called productCode
    Code:
    DoCmd.OpenReport "rptProductOrdersEnquiry", acViewReport, , "[Product]='" & productCode & "'"

    Thanks guys

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

Similar Threads

  1. Replies: 10
    Last Post: 04-10-2018, 03:19 PM
  2. Replies: 10
    Last Post: 04-19-2017, 09:42 AM
  3. Replies: 4
    Last Post: 05-01-2014, 10:57 AM
  4. docmd.open report 'where' clause
    By khumbo in forum Reports
    Replies: 4
    Last Post: 02-19-2013, 01:14 PM
  5. Help on where clause of open form
    By Madmax in forum Access
    Replies: 5
    Last Post: 06-23-2011, 11:19 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