Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP - strWhere problems in DoCmd.OpenReport

Status
Not open for further replies.

HenryE

IS-IT--Management
Apr 30, 2002
42
US
Hi,

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?

Thanks.

Henry
 
Replace this:
strWhere2 = strWhere1 & " And [Student] = '" & Me.StudentName2 & "'"
By this:
strWhere2 = strWhere1 & " Or [Student] = '" & Me.StudentName2 & "'"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks. (smacks own head). It works fine now.

Henry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top