Solved

Sntax SQL error using OpenRecordSet

Posted on 2003-11-09
4
512 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
Comment Utility
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
Comment Utility
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 33

Expert Comment

by:Mike Eghtebas
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now