Solved

sql vba excel 2010 ado query syntax

Posted on 2014-04-10
2
688 Views
Last Modified: 2014-04-10
Hello EE,

I am having an issue getting my records out of an table in excel 2010 using ado.

This statement returns 146 records fine:

rst.Open "SELECT [IndexKey], [Details], [Name], [Amount], [Name] FROM [tbl_import] ORDER by [Name]", cnn, adOpenStatic

Open in new window


As soon as I add some criteria, it does not:

rst.Open "SELECT [IndexKey], [Details], [Name], [Amount], [Code] FROM [tbl_import] WHERE ((([Code]) Is Null)) ORDER BY [Name]", cnn, adOpenStatic

Open in new window


Anyone got the solution? Its got me stumped!

TA
0
Comment
Question by:discogs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39993266
it does not ...

a. return anything
b. return what I expect

?

I'm assuming a.

Your criteria is to search for Code IS NULL
Perhaps there aren't any records where that is true" Maybe Code looks empty but isn't?

e.g.
SELECT
      [IndexKey]
    , [Details]
    , [Name]
    , [Amount]
    , {Code}
FROM [tbl_import]
WHERE ({Code} IS NULL OR {Code} = '')
ORDER BY
      [Name];

nb: I had to substitute { } for [ ] around the word "code"
0
 

Author Comment

by:discogs
ID: 39993355
Paul
Thanks for your response.

Interesting points you make. I ran a test against the cell and realised that there is a formula inside there which is why its not returning any records.

Thanks for the tip, I am going to have to approach this a different way.

TA
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question