Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem looking up a value in a query

Posted on 2013-10-22
4
Medium Priority
?
282 Views
Last Modified: 2013-10-22
Hello Experts
I am having a bit of a problem getting a query to work.  I am looking for a list of records where the Renewal Date value is within a certain number of weeks.
I have the query working fine with a hardcoded value for weeks.  When I add a lookup for the value I get:
Syntax error (missing operator) in query expression 'Membership warning weeks'

This is the query that I am trying:

*****************************************************************
SELECT tblClients.[Client ID], tblClients.RenewalDate, tblClients.NextRenewalDate, [tblClients.Title] & " " & [tblClients.Firstname] & " " & [tblClients.Lastname] & " - " & [tblClients.Address 1] & " " & [tblClients.Address 2] & " " & [tblClients.Town] AS ClientFullnameAddress
FROM tblClients
WHERE (((tblClients.RenewalDate)<DateAdd("w",DLookUp("Membership warning weeks","tblParameters"),Date())) AND ((tblClients.NextRenewalDate) Is Null));
**********************************************************************

Hope someone can give me a clue.

Regards

Richard
0
Comment
Question by:rltomalin
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1200 total points
ID: 39590670
Since the field name has spaces in it, try using square brackets around it:

SELECT tblClients.[Client ID], tblClients.RenewalDate, tblClients.NextRenewalDate, [tblClients.Title] & " " & [tblClients.Firstname] & " " & [tblClients.Lastname] & " - " & [tblClients.Address 1] & " " & [tblClients.Address 2] & " " & [tblClients.Town] AS ClientFullnameAddress
FROM tblClients
WHERE (((tblClients.RenewalDate)<DateAdd("w",DLookUp("[Membership warning weeks]","tblParameters"),Date())) AND ((tblClients.NextRenewalDate) Is Null));

Open in new window

0
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 800 total points
ID: 39590690
Are you doing this in code or in the query designer.  If code, should be:

"WHERE tblClients.RenewalDate) < #" & Format(DateAdd("w",DLookUp('Membership warning weeks','tblParameters'),Date()),'mm/dd/yy') & "# AND tblClients.NextRenewalDate Is Null;"

If the query designer, define a column as:

DateAdd("w",DLookUp("Membership warning weeks","tblParameters"),Date())

and then put the criteria on it.

As an aside, you really should not be using a Dlookup() inside a SQL statement.   THe domain functions were intended to be used in places where SQL statements are not allowed.  

Using one will always give you poor performance on your query as the query parser cannot optimize the execution.

Jim.
0
 

Author Closing Comment

by:rltomalin
ID: 39590753
I used mbizup's solution and it worked fine.  I had actually moved ahead when the second solution came in, but gave it some points because I am sure it would have been OK and the expert took the trouble to give some advice.

Regards

Richard
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

972 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