Solved

Sntax SQL error using OpenRecordSet

Posted on 2003-11-09
4
515 Views
Last Modified: 2010-08-05
What is wrong with this code?

Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [E-mail address] FROM [Broker Contacts] where [E-mail address] is not null  and [Broker Contacts].[contact name]=[Forms]![Loan Information]![Contact Name]")

I Get ERROR 3061,  Too few Parameters, Expected one"

THEN

I tried this instead:
 Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [E-mail address] FROM [Broker Contacts] where [E-mail address] is not null and [Broker Contacts].[contact name]=" & Me("contact Name") & "")

I get ERROR 3075, Sntax error,  (missing operator) in query expression ' [E-mail address] is not null and [Broker Contacts].[contact name]=Rob Martin'.

Any ideas????
0
Comment
Question by:BonnyFreund
4 Comments
 
LVL 3

Accepted Solution

by:
Drizzt95 earned 125 total points
ID: 9711235
Try this instead:

Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [E-mail address] FROM [Broker Contacts] where [E-mail address] is not null  and [Broker Contacts].[contact name]= '" & [Forms]![Loan Information]![Contact Name] & "'")
0
 
LVL 9

Assisted Solution

by:svenkarlsen
svenkarlsen earned 125 total points
ID: 9711256
Hi BonnyFreund,

When referring to [Contact Name], it need to be quoted in the string, - i.e.: a single quote must be put in front and behind the [Contact Name]:

 Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [E-mail address] FROM [Broker Contacts] where [E-mail address] is not null and [Broker Contacts].[contact name]='" & Me("contact Name") & "'")

Kind regards,
Sven
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 9711647
Two points,

- Use chr(34) to handle single quete required  in the SQL syntax and single quote inside a name like O'Conner:

 Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [E-mail address] FROM [Broker Contacts] where [E-mail address] is not null and [Broker Contacts].[contact name]=" & chr(34) & Me("contact Name") & CHR(34))

- In case where you have a name but no email, it may exclude even without "[E-mail address] is not null and".  If you need on purpose to show missing emails for you to fill them in, above SQL need some more revisions.

Mike
0
 

Author Comment

by:BonnyFreund
ID: 9711673
Cheers to you both.  I knew it was something silly like a missing tick mark, I just was tired of guessing the syntax.  I appreciate both of your help!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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 how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

828 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