Solved

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

Posted on 2010-11-15
3
772 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

832 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