Solved

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

Posted on 2010-11-15
3
773 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 - Microsoft MVP, Access and Data Platform) 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
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…

830 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