Results 1 to 7 of 7
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Help opening report from form using form criteria


    I am having trouble coding a openreport code. Basically I have a button in my form to open a report, and the criteria for the report should be based on whatever entry the user is on in the form. I am using the below code but it is not applying the criteria. Any idea what I'm doing wrong? The report's record source is qryComplaints and 'complaintnumber' is a number field.

    Code:
    Private Sub btnOpenReport_Click()
        DoCmd.OpenReport "rptFormReport", acViewReport, [ComplaintNumber] = Forms![frmComplaints]![ComplaintNumber], acDialog
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Maybe try:
    Code:
        DoCmd.OpenReport "rptFormReport", acViewReport,, "[ComplaintNumber] = " & Forms![frmComplaints]![ComplaintNumber], acDialog
    EDIT: added a missing comma, your original code was adding the Filter instead of setting the Where condition
    expression.OpenReport (ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    That worked! Thanks so much!

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Actually one more question...say it wasn't a number field, would it be coded the same? (lets say for a short text field)

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Similar but you need to wrap it in single quotes (or double double quotes in case the text would include a single quote like in O'Brian):
    Code:
    DoCmd.OpenReport "rptFormReport", acViewReport,, "[ComplaintNumber] = '" & Forms![frmComplaints]![ComplaintNumber] & "'", acDialog
    DoCmd.OpenReport "rptFormReport", acViewReport,, "[ComplaintNumber] = """ & Forms![frmComplaints]![ComplaintNumber] & """", acDialog
    For dates you wrap them in #.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Thank you!

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

Similar Threads

  1. Replies: 5
    Last Post: 04-28-2019, 01:44 PM
  2. Opening a form based on criteria
    By Jen0dorf in forum Access
    Replies: 3
    Last Post: 08-27-2016, 09:15 AM
  3. Opening a report using criteria from a form
    By craig1988 in forum Forms
    Replies: 4
    Last Post: 08-22-2016, 08:23 AM
  4. Replies: 1
    Last Post: 01-10-2012, 03:44 AM
  5. Link Criteria no working when opening new form
    By ETCallHome in forum Forms
    Replies: 1
    Last Post: 06-17-2011, 05:26 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