Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-15
3
Medium Priority
?
789 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
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…
Suggested Courses

824 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