OpenRecordset Syntax failing

I'm successfully using the following to bring up data from a table.  

    sqlStr = "SELECT * FROM tDr as sDr"

    '"SELECT tDr.LName, tDr.LName FROM tDr WHERE (((tDr.Lisc) Is Not Null)) ORDER BY tDr.LName;"

    Set db = CurrentDb
    Set rs = db.OpenRecordset(sqlStr)

    rs.MoveFirst

    Do While Not rs.EOF
      sDr = sDr & "Dr. " & rs!FName & " " & rs!LName & ", "
      iDrCount = iDrCount + 1
      If (iDrCount) Mod 3 = 0 Then sDr = sDr & vbCrLf   '3 Drs per signature line
      rs.MoveNext
    Loop
    
    rs.Close 'Close the recordset
    Set rs = Nothing 'Clean up

Open in new window


Now I want to add a criteria... where Lisc in the Table Dr is not null.  Same code but with:

sqlStr = "SELECT * FROM tDr WHERE ((tDr.Lisc) Is Not Null) as sDr"

Open in new window


With this change the code fails.  Is my syntax off?  Its working in a plan old query but not in the code.
thandelAsked:
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.

NorieAnalyst Assistant Commented:
What are you trying to do with this part of the SQL statement?
as sDr

Open in new window

0
thandelAuthor Commented:
This was implemented as a string (recommended by EE) so I can add text to the search with each find.  Basically to put "Dr" at the front of the results

sDr = sDr & "Dr. " & rs!FName & " " & rs!LName & ", "
0
thandelAuthor Commented:
Hmm now that you ask I changed it to:

sqlStr = "SELECT * FROM tDr WHERE ((tDr.Lisc) Is Not Null)"

That seems to work.  Is that the correct approach?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

NorieAnalyst Assistant Commented:
Isn't that the same as the original query?
0
Dale FyeOwner, Developing Solutions LLCCommented:
thandle,

the query:
SELECT * FROM tDr as sDr

Open in new window

simply provides an alias for the table (tDr) which is not really needed when creating a recordset. With a table name that short, I would never create an alias for the table name in a query, but if you had a table named "tblDoctorPointsOfContact", I would alias that with something like: "tDPOC"

HTH
Dale
0
thandelAuthor Commented:
Norie: Isn't that the same as the original query?

No simliar but without the as sDr

Dale: Thanks with my working change was that the proper syntax aside from your suggestion?
0
Dale FyeOwner, Developing Solutions LLCCommented:
Yes, that syntax should work,

sqlStr = "SELECT * FROM tDr WHERE ((tDr.Lisc) Is Not Null)"

although you really don't need the parenthesis.  Access will add them automatically, and I generally like to wrap each criteria in a single set of parentheses, for clarity, like:

sqlStr = "SELECT * FROM tDr WHERE (tDr.Lisc Is Not Null)"

Dale
0

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
Fabrice LambertFabrice LambertCommented:
To make it even simplier:
sqlStr = "SELECT * FROM tDr WHERE Lisc Is Not Null;"

Open in new window

Unless there are ambiguities, the table name is optional in front of column names.
0
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.