Solved

Sntax SQL error using OpenRecordSet

Posted on 2003-11-09
4
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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