Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Unanswered: HEEELP - strWhere Problems with DoCmd.OpenReport


    This should be very simple, but I can't make it work.

    I'm trying to open a report from a form using DoCmd.OpenReport and two criteria (choosing records that have student names that match two possibilities).

    It works with one criteria, as follows:

    Dim strWhere as String

    strWhere = "[Student] = '" & Me.StudentName1 & "'"

    DoCmd.OpenReport stDocName, acPreview, , strWhere

    The above seems to work perfectly fine.

    However, when I try to go to two criteria, I get errors. For example, the following does not work:

    Dim strWhere1 as String
    Dim strWhere2 as String

    strWhere1 = "[Student] = '" & Me.StudentName1 & "'"
    strWhere2 = strWhere1 & " And [Student] = '" & Me.StudentName2 & "'"

    DoCmd. OpenReport stDocName, acPreview, , strWhere2

    The above does not work. I've tried changing it a bunch of different ways, based on dozens of examples I got off the Internet, but nothing works.

    I'm pretty new to VBA. Does anyone know what I'm doing wrong?



  2. #2
    Join Date
    Jan 2004

    Oops. Needed an Or, not an And

    Obviously, I needed to be using an Or, not an And.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts