Solved

Syntex error when Set rs = CurrentDb.OpenRecordset in access form

Posted on 2010-11-15
3
770 Views
Last Modified: 2012-05-10
Hi I have a form.
I have combo field IsT1 and a Text field Email1.
Based on what they selet on IsT1, I like to populate Email1  the email field for the full name from table tblEmployees.
On the On After update event I have the following code

 Private Sub IsT1_AfterUpdate()
Dim db As DAO.Database
 Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("select EmailA from tblEmployees where Fullname = " & Me.IsT1)
    Me.Email1 = rs!EmailA
End Sub

I get the following error

Syntex eror(missing opertor) in query expression Fullname = displays name '
Please advice what I'm doing wrong in my syntex
0
Comment
Question by:Sivasan
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 34138411
try this:

Set rs = CurrentDb.OpenRecordset("select EmailA from tblEmployees where Fullname = " & Chr(34) & Me.IsT1 & Chr(34) )
    Me.Email1 = rs!EmailA
End Sub

mx
0
 

Author Comment

by:Sivasan
ID: 34138437
Great you are awesome!! Thankss a lott
0
 
LVL 75
ID: 34138465
Because Me.IsT1 is a Text value (String), it needs to be surrounded by Double Quotes in Criteria as such.  Chr(34) is a double quote.   Dates must be surrounded by the # sign.  Numeric w/b the way you initially had it.

mx
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…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

760 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

20 Experts available now in Live!

Get 1:1 Help Now