Results 1 to 12 of 12
  1. #1
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24

    Open Report with 2 conditions

    Ok so I have my database about complete, just working on more dynamic reports. I have 5 standard reports set up. I then set them up so I could filter by one of the fields. I was just asked to add a data range to the report now. I was able to create a date range report for the overall data and was trying to get it to include the other varibale. Below is what I have so far but it opens blank. What am I missing?



    DoCmd.OpenReport strReport, lngView, , strWhere & "AND [Project worksheet] = '" & Me.PW_Filter & "'"

    StrReport is the report name. StrWhere is the data ranges (it works if I end the command here). I added the variable & "AND XXXXXXXX" which works seperately to bring up all records that match my PW_Filter.

  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,641
    Does this work (added space)?

    DoCmd.OpenReport strReport, lngView, , strWhere & " AND [Project worksheet] = '" & Me.PW_Filter & "'"

    If not, try this technique to print out the finished string to the Immediate window:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    Nope, I did test it with no selection in the PW_Filter filter and it still came up blank.

  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,641
    So, did you use that technique to print out the finished string?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    Not sure why there are 2 output lines and not sure why it says 2011. I have 2012 in the entry field.

    StrWhere = [Project worksheet] = '2001' And ([Date_Worked] >= #04/01/2011#) AND ([Date_Worked] < #05/02/2012#)

    The immediate out is
    ([Date_Worked] >= #01/01/2011#) AND ([Date_Worked] < #05/02/2012#)
    ([Date_Worked] >= #04/01/2011#) AND ([Date_Worked] < #05/02/2012#)

  6. #6
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    Here is the code, I played around and created a variable for the project worksheet field so I can reuse once it's working.

    Const strcJetDate = "\#mm\/dd\/yyyy\#"
    strReport = "Time by Project Worksheet" 'Replace for Report Name.
    strWhat = "[Project worksheet] = '" & Me.PW_Filter & "'" 'Replace for new report type.
    strDateField = "[Date_Worked]" 'Replace for Date Field
    lngView = acViewPreview
    strWhere = strWhat & " AND "
    If IsDate(Me.txtStartDate) Then
    strWhere = strWhere & "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
    End If
    If IsDate(Me.txtEndDate) Then
    If strWhere <> vbNullString Then
    strWhere = strWhere & " AND "
    End If
    strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
    End If

    If CurrentProject.AllReports(strReport).IsLoaded Then
    DoCmd.Close acReport, strReport
    End If
    Debug.Print strWhere
    DoCmd.OpenReport strReport, lngView, , strWhere

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    So it's working now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    No sorry if I confused. It still isnt working. Weird thing is I tried a fwe different selections and sometimes it worked but mostly came up blank. I checked the data and my options should have generated data.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Can you post the db here, or a representative sample?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    AL_Project_Worksheets - Copy.zipAL_Project_Worksheets - Copy.zip

    I stripped out some of the other stuff to just leave the 1 report I was working on, I can apply to the others in my actual db version. I left in some test data though so you can see. I am trying to get the report to populate with both a date selection and project selected. Thanks!

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Unless I'm missing something, nothing is returned because the data doesn't match up. The Project Worksheet field contains values like:

    MABMJ01
    Multiple

    not

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

  12. #12
    rck3 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    24
    Thanks, let me load the real data and try it. Sometimes you get so focused on code issues you forget you might have bad data. I just removed all data and entered in new test data and it did seem to work. I will try it with the full data and let you know. Thanks

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

Similar Threads

  1. open report after search
    By shirvo in forum Reports
    Replies: 5
    Last Post: 01-24-2011, 12:21 AM
  2. Replies: 5
    Last Post: 06-19-2010, 07:55 PM
  3. Report won't open
    By okakopa in forum Reports
    Replies: 1
    Last Post: 05-24-2010, 04:09 AM
  4. if...then conditions ???
    By em07189 in forum Access
    Replies: 6
    Last Post: 03-05-2010, 10:29 PM
  5. open report from a vb form
    By tracamonali in forum Reports
    Replies: 2
    Last Post: 08-10-2009, 01:55 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