Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 17th, 2004, 04:39 PM
Authorized User
 
Join Date: Jun 2003
Location: Irvine, CA, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default Quotes in SQL String Retrieving Access Data

Hi.

I have this issue with a SQL statement that uses strings as part of the Where clause. I search this database for similar situations, found some responses and tried them but still could not get my code to work.

I'm using VB 6.0 to retrieve some rows from an MS Access table.
Here's my code:
 sSql = "Select * From SCR_Log Where BaseSCRID = " & lBaseSCRID
 sSql = sSql & " And EmailSubject = '" & constantAValue
 sSql = sSql & "' And UsedFlag = " & constantNo
 oRS.Open sSql, oConn, adOpenDynamic, adLockOptimistic

Here's the value of SQL after setting it as above in VB Watch mode:
"Select * From SCR_Log Where BaseSCRID = 45000 And EmailSubject = 'SCR2K2 Email Notification Change' And UsedFlag = No"

BaseSCRID is a Number, EmailSubject is Text and UsedFlag is Yes/No.

I also tried using double quotes but that didn't work either.
Here's the value of sSql with double quotes that also does not work:
"Select * From SCR_Log Where BaseSCRID = 45000 And EmailSubject = "SCR2K2 Email Notification Change" And UsedFlag = No"

Another thing I tried to use was chr(34) but still no success.

Any suggestions would be greatly appreciated.

Rita
Reply With Quote
  #2 (permalink)  
Old November 17th, 2004, 04:50 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you try this: in query change UsedFlag = No " to UsedFlag = 0?
bfurman.

Reply With Quote
  #3 (permalink)  
Old November 17th, 2004, 04:53 PM
Authorized User
 
Join Date: Sep 2004
Location: Twickenham, , United Kingdom.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Paulsh Send a message via Yahoo to Paulsh
Default

Hello,

It seems you might have made a small error. The sql result should look like this when you debug it:

Select * From SCR_Log Where BaseSCRID = '45000' And EmailSubject = 'SCR2K2 Email Notification Change' And UsedFlag = 'No'

To get it to look like that your sqlstring should be like this:

sSql = "Select * From SCR_Log Where BaseSCRID = " & "'" & lBaseSCRID & "'" & _
" And EmailSubject = '" & constantAValue & "' And UsedFlag = " & _ "'" & constantNo & "'"

Hope that helps
Paul

Paul
Reply With Quote
  #4 (permalink)  
Old November 17th, 2004, 05:04 PM
Authorized User
 
Join Date: Jun 2003
Location: Irvine, CA, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to all for your replies.

I did some further searching on this site and this time searched for the error message I was getting - "No value given for one or more required parameters".

I found one reply where it was stated that one of the parameters could be misspelled. I checked the table design (I had already done this) and on looking closely at the "EmailSubject" column saw that it actually was "Email Subject"!!

That was my problem - a misspelled parameter. I made the fix and this time the code worked (I used the one with the double quotes).
Reply With Quote
  #5 (permalink)  
Old November 17th, 2004, 05:53 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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

If BaseSCRID is a number, i.e. 4500, then there should be no quotes around it. Also, the Yes/No is a flag which is -1 or zero or True or False. Therefore, your end result should look like this.

"Select * From SCR_Log Where [BaseSCRID] = 45000 And [EmailSubject] = 'SCR2K2 Email Notification Change' And [UsedFlag] = False"

To get it to look like that your sqlstring should be like this:

sSql = "Select * From SCR_Log Where [BaseSCRID] = " & lBaseSCRID & _
" And [EmailSubject] = '" & constantAValue & _
"' And [UsedFlag] = False"


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #6 (permalink)  
Old November 17th, 2004, 06:04 PM
Authorized User
 
Join Date: Jun 2003
Location: Irvine, CA, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the clarification Greg.

It is as you say but I also got it to work when I checked the Yes/No flag for No in the SQL statement. As long as there were no quotes around the NO it worked.

Rita
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Double Quotes from a string Durkee VB.NET 2002/2003 Basics 12 October 4th, 2007 12:10 PM
how to return string value with quotes (single or tllcll BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 November 10th, 2005 01:57 PM
retrieving data in excel from access. yesilkalem Access 1 May 25th, 2004 04:19 PM
Retrieving Query String a5xo3z1 Beginning PHP 12 June 19th, 2003 12:55 PM



All times are GMT -4. The time now is 08:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.