thandel
asked on
Proper syntax to use a querry in a string with VBA
I have the following query which is working in MS Access 2003:
SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub, tLenSupplier.LastSubResult FROM tLenSupplier WHERE (((tLenSupplier.LastSub)<> IsNull("La stSub"))) OR (((tLenSupplier.LastSubRes ult)<>IsNu ll("LastSu bResult")) ) ORDER BY tLenSupplier.LSupplier"
I would like to place this into a string to use in VBA for other purposes. I am having trouble converting the query into a string to set the variable "sSql" --> (Set rs = CurrentDb.OpenRecordset(sS ql))
Any assistance is appreciated. Thank you.
SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub, tLenSupplier.LastSubResult
I would like to place this into a string to use in VBA for other purposes. I am having trouble converting the query into a string to set the variable "sSql" --> (Set rs = CurrentDb.OpenRecordset(sS
Any assistance is appreciated. Thank you.
EDITED...because i am trying to guess...the IsNull is applied on a field to check if its Null or Not..
Either you are matching against a word or maybe Nulls....so you need Nz like
Nz(LastSub,"")
Either you are matching against a word or maybe Nulls....so you need Nz like
Nz(LastSub,"")
Your query makes no sense, so it would be better if you describe in plain English what you are trying to accomplish.
ASKER
Thanks John but if I set your first solution to a string variable I get an error. I tried this:
sSql = "SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub,tLenS upplier.La stSubResul t FROM tLenSupplier WHERE (tLenSupplier.LastSub <> "LastSub" OR (tLenSupplier.LastSubResul t <> "LastSubResult")) ORDER BY tLenSupplier.LSupplier"
That is the issue I'm having... I need to set to a string so use in a variable.
sSql = "SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub,tLenS
That is the issue I'm having... I need to set to a string so use in a variable.
That would be:
sSql = "SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub,tLenSupplier.LastSubResult FROM tLenSupplier WHERE (tLenSupplier.LastSub <> 'LastSub' OR (tLenSupplier.LastSubResult <> 'LastSubResult')) ORDER BY tLenSupplier.LSupplier"
I'm with Gustav as far as making sense of your query goals.
If we just look at the first condition of the where clause...
The same questions apply to the second condition in your query.
If we just look at the first condition of the where clause...
WHERE (((tLenSupplier.LastSub)<>IsNull("LastSub")))
The condition is obscure, but as written it is testing to see if the literal constant "LastSub" is not null. Of course it isn't, therefore IsNull("LastSub") is a long winded way of saying FALSE, and so the condition is reallyWHERE (((tLenSupplier.LastSub)<>FALSE
Is this your intention? Is the field LastSub in the table tLenSupplier a Boolean field?The same questions apply to the second condition in your query.
If you don't share a small sample bof your data..I am afraid we are playing the Guessing game.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Gustav has it... I just needed to take an existing query that was working and change it for variable use. I always have issues with the quotes. Thank you.
ASKER
Sorry Pat I just saw you comment and you are 100% right....
The chosen solution didn't have anything for a null value and you followed what a I needed with:
sSQL = "SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub, tLenSupplier.LastSubResult FROM tLenSupplier WHERE tLenSupplier.LastSub Is Not Null OR tLenSupplier.LastSubResult Is Not Null ORDER BY tLenSupplier.LSupplier"
Is there a way I can change my chosen solution?
The chosen solution didn't have anything for a null value and you followed what a I needed with:
sSQL = "SELECT tLenSupplier.LSupplier, tLenSupplier.LastSub, tLenSupplier.LastSubResult
Is there a way I can change my chosen solution?
I believe that there is a button you see that I don't that lets you call a moderator to undo you acceptance.
Open in new window