Access VBA .... Quotes!

See attached code
How do I add to the where clause a second condition ... being .... len(TransDesc)=0.
The quotes are confusing me (again!)

Var = CurrentProject.Connection.Execute( _
"SELECT COUNT(*) FROM tblBankAIB " _
& " WHERE AIBCreditValue<>0 ").Collect(0)

MsgBox "There are " & Var & " lodgements with no Giro reference"



End Sub

Open in new window

Patrick O'DeaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IrogSintaCommented:
Try this:
"SELECT COUNT(*) FROM tblBankAIB " _
& " WHERE AIBCreditValue<>0 AND Len(TransDesc)=0").Collect(0)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Patrick O'DeaAuthor Commented:
Thx!  Easy one!
Dale FyeOwner, Developing Solutions LLCCommented:
The best way to do this is to build the SQL before the Execute method, so that you can debug it until it is correct.  

Plus, you cannot set the value of a variable to the results of an EXECUTE method.

Dim rs as DAO.Recordset
strSQL = "SELECT COUNT(*) as Lodgements FROM tblBankAIB " _
             & "WHERE AIBCreditValue<>0"
debug.print strSQL
set rs = currentdb.openrecordset(strSQL, , dbfailonerror)
Var = rs!Lodgements
rs.close
set rs = nothing

MsgBox "There are " & Var & " lodgements with no Giro reference"

Open in new window

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Dale FyeOwner, Developing Solutions LLCCommented:
Ron, what is that:

.Collect(0)

syntax?  I've never seen that before?
IrogSintaCommented:
You're right, Dale.  I didn't even pay attention to that.  I would normally use:
           .Fields(0)
In order to get the result of the first field.
Dale FyeOwner, Developing Solutions LLCCommented:
@Ron,  I've never seen that done in an Execute method, and cannot figure out how to do that.

I assume that you were thinking that the OP was opening a recordset, not trying to retrieve data through an Execute method.  Is that correct?

@Dewsbury,

Did you even try that syntax in the context you provided?  If so, and it worked, could you please post what worked for you, because I've never seen it done that way before.

Dale
IrogSintaCommented:
@Dale, I looked into it and apparently the syntax is correct.  It is used for ADO connections.  I even did a quick test and it works.  I think we both learned something new :-)

Ron
Dale FyeOwner, Developing Solutions LLCCommented:
Thanks, Ron.

I so rarely use ADO, that I didn't pickup on that syntax:

CurrentProject.Connection.Execute

I was focused on the Execute.
Patrick O'DeaAuthor Commented:
As the OP .... I must confess that the Collect.(0) syntax was cut and pasted from elsewhere..... (perhaps contrary to best practice)!
Dale FyeOwner, Developing Solutions LLCCommented:
21Dewsbury,

No, don't assume that at all.  I just rarely use ADO, so didn't recognize the syntax.  It's good when even the experts get a chance to learn something new.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.