Solved

Problem looking up a value in a query

Posted on 2013-10-22
4
275 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 300 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 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 200 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

856 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