Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2004, 04:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 126
Thanks: 5
Thanked 0 Times in 0 Posts
Default Where condition in VBA

Can someone please tell me what I have wrong in this line of code?

Code:
Dim Spec As String
Spec = InputBox("Please enter the specification number with an * on each end", "Spec number please")
Docmd.OpenReport "Print Specification Listing",acViewPreview,,Where [Parts]![Specification] Like Spec or [Parts]!BOMSpecification] Like Spec
Parts = the table name
Specification = field name in the table
BOMSpecification = field name in the table

My problem is in the Where clause. What I want it to do is only show the records that contains (in either field) what they enter in the input box.

Thanks for your help!




Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!
__________________
Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!
 
Old May 5th, 2004, 05:13 PM
Authorized User
 
Join Date: Nov 2003
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need quotation marks around your WHERE condition. Change it to read as follows:


Docmd.OpenReport "Print Specification Listing",acViewPreview,,"[Parts]![Specification] Like """ & Spec & """ or [Parts]!BOMSpecification] Like """ & Spec & """"


That should do the trick.

Darrell L. Embrey
 
Old May 6th, 2004, 07:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 126
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thank you for your reply Darrell.
I updated the code as you said, but now I am getting a runtime error 3075.
The message with it reads as follows:
Quote:
quote:Syntax error (missing operator) in query expression '(Where
[Parts]![Specification] Like "d 2000" or [Parts]![BOMSpecification]
Like "d 2000")'.
Here is what my whole set of code looks like now:

Code:
Private Sub cmdPrintSpec_Click()
Dim Spec As String

Spec = InputBox("Please enter the specification number with an * on 
each end", "Spec number please")

DoCmd.OpenReport "Print Specification Listing", acViewPreview, , 
"Where [Parts]![Specification] Like """ & Spec & """
or [Parts]![BOMSpecification] Like """ & Spec & """", acWindowNormal
End Sub
Thanks in advance for any help!

Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!
 
Old May 6th, 2004, 10:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Copy and paste this exactly. Note, in a DoCmd.OpenReport statement, the word "where" is assumed. You do NOT put it in the code at all.

Code:
DoCmd.OpenReport "Print Specification Listing", acViewPreview, , _
"[Parts]![Specification] Like '*" & Spec & _
"*' or [Parts]![BOMSpecification] Like '*" & Spec & "*'", acWindowNormal
Note, since you used the specifier "like" then you must surround SPEC with wildcards, too.

In a query: Like "*Text Here*"

In Code:
Code:
Like '*" & Spec & "*'"

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old May 6th, 2004, 10:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Oops, I mean

In a query: Like "*Text Here*"

In Code:
Code:
Like '*" & Spec & "*'"
I fixed the apostrophe.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old May 6th, 2004, 11:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 126
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Worked perfect...THANK YOU SO MUCH!!!

Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!





Similar Threads
Thread Thread Starter Forum Replies Last Post
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
Help with writing if condition jendys XSLT 9 April 30th, 2007 04:02 AM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.