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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Criteria from VBA

Status
Not open for further replies.

cP6uH

Programmer
May 21, 2003
17
0
0
CA
Hi,
I have a little problem.

If I do following code in VBA, and try to run a report, it works fine, and it filters all the records for the name Jason.

sCriteria = "[Name]= 'Jason'"
stDocName = "Query"
DoCmd.OpenReport stDocName, acViewPreview, , sCriteria, acWindowNormal


But, when I do the following code:

strTest = "Jason"
sCriteria = "[Name] = '" & strTest & "'"
stDocName = "Query"
DoCmd.OpenReport stDocName, acViewPreview, , sCriteria, acWindowNormal

I get input box that asks for Parameter Value for Name field.

What am I doing wrong?

Thanks,

Dragan



 
I have never been a fan of the "multiple inverted comma"
thing - especially when you need to debug it. So, try the
following:

Instead of sCriteria = "[Name] = '" & strTest & "'"
do sCriteria = "[Name] = " & chr(34) & strTest & chr(34)

chr(34) is the inverted commas (") character

See if that does the trick.

Regards...

 
Try

strTest = "Jason"
sCriteria = "Name = '" & strTest & "'"
stDocName = "Query"
DoCmd.OpenReport stDocName, acViewPreview, , sCriteria, acWindowNormal
 
Sorry guys... The code that I've put up works fine...
In my original code I had a spelling and that's why it was looking for that Parameter value.... because the field didn't exist in the query.

Sorry once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top