473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Joining two fields in a query

AllusiveKitten
Hi

I am hoping someone can assist me, I have just created a query in Access where I have joined 2 fields ie FirstName & Surname to bring back the value "FirstName Surname". I am then trying to be able run a query for the full value. This is all working fine in the query until I copy the SQL statement to Visual basic.

Set db = CurrentDb()
lsql = "SELECT [TblList_RecipientDetails]![FirstName] & " " & [TblList_RecipientDetails]![Surname] AS Expr1, TblList_RecipientDetails.FirstName, TblList_RecipientDetails.Surname, TblList_RecipientDetails.AddressName, TblList_RecipientDetails.[Project/OfficeName], TblList_Addresses.Address1, TblList_Addresses.Address2, TblList_Addresses.Address3, TblList_Addresses.City, TblList_Addresses.State, TblList_Addresses.PostCode, TblList_Addresses.Country, TblList_RecipientDetails.Current, TblList_RecipientDetails.DeativateDate FROM TblList_RecipientDetails INNER JOIN TblList_Addresses ON TblList_RecipientDetails.[Project/OfficeName] = TblList_Addresses.[Project/OfficeName] WHERE ((([TblList_RecipientDetails]![FirstName] & " " & [TblList_RecipientDetails]![Surname])='" & Txt_RecipientName & "')));"
Set lrs = db.OpenRecordset(lsql)

It is here that I get an error "Expected end of statement" and the bolded area hightlighted.

Can anyone see where I have made the error, or left something off.

Thank you for your help

AK
Oct 1 '07 #1
4 1337
hariharanmca
1,977 1GB
Expand|Select|Wrap|Line Numbers
  1. lsql = "SELECT [TblList_RecipientDetails]![FirstName]  [TblList_RecipientDetails]![Surname] AS Expr1, TblList_RecipientDetails.FirstName, TblList_RecipientDetails.Surname, TblList_RecipientDetails.AddressName, TblList_RecipientDetails.[Project/OfficeName], TblList_Addresses.Address1, TblList_Addresses.Address2, TblList_Addresses.Address3, TblList_Addresses.City, TblList_Addresses.State, TblList_Addresses.PostCode, TblList_Addresses.Country, TblList_RecipientDetails.Current, TblList_RecipientDetails.DeativateDate FROM TblList_RecipientDetails INNER JOIN TblList_Addresses ON TblList_RecipientDetails.[Project/OfficeName] = TblList_Addresses.[Project/OfficeName] WHERE ((([TblList_RecipientDetails]![FirstName]  [TblList_RecipientDetails]![Surname])='" & Txt_RecipientName & "')));"
  2. Set lrs = db.OpenRecordset(lsql)
  3.  
Try this query
Oct 1 '07 #2
QVeen72
1,445 Expert 1GB
Hi

I am hoping someone can assist me, I have just created a query in Access where I have joined 2 fields ie FirstName & Surname to bring back the value "FirstName Surname". I am then trying to be able run a query for the full value. This is all working fine in the query until I copy the SQL statement to Visual basic.

Set db = CurrentDb()
lsql = "SELECT [TblList_RecipientDetails]![FirstName] & " " & [TblList_RecipientDetails]![Surname] AS Expr1, TblList_RecipientDetails.FirstName, TblList_RecipientDetails.Surname, TblList_RecipientDetails.AddressName, TblList_RecipientDetails.[Project/OfficeName], TblList_Addresses.Address1, TblList_Addresses.Address2, TblList_Addresses.Address3, TblList_Addresses.City, TblList_Addresses.State, TblList_Addresses.PostCode, TblList_Addresses.Country, TblList_RecipientDetails.Current, TblList_RecipientDetails.DeativateDate FROM TblList_RecipientDetails INNER JOIN TblList_Addresses ON TblList_RecipientDetails.[Project/OfficeName] = TblList_Addresses.[Project/OfficeName] WHERE ((([TblList_RecipientDetails]![FirstName] & " " & [TblList_RecipientDetails]![Surname])='" & Txt_RecipientName & "')));"
Set lrs = db.OpenRecordset(lsql)

It is here that I get an error "Expected end of statement" and the bolded area hightlighted.

Can anyone see where I have made the error, or left something off.

Thank you for your help

AK
Hi,

Some problem with ur Where Condition , there is no operator after Firstname...

Try this where condition :
" Where [TblList_RecipientDetails]![FirstName] & ' ' & [TblList_RecipientDetails]![Surname])='" & Txt_RecipientName & "' ;"


Change Expr1 also this Way:

SELECT [TblList_RecipientDetails]![FirstName] & ' ' & [TblList_RecipientDetails]![Surname] AS Expr1

This is may avoid confusion of double quotes...

Regards
Veena
Oct 1 '07 #3
hariharanmca
1,977 1GB
Expand|Select|Wrap|Line Numbers
  1. lsql = "SELECT ([TblList_RecipientDetails]![FirstName] & [TblList_RecipientDetails]![Surname]) AS fldRecipientName, TblList_RecipientDetails.FirstName, TblList_RecipientDetails.Surname, TblList_RecipientDetails.AddressName, TblList_RecipientDetails.[Project/OfficeName], TblList_Addresses.Address1, TblList_Addresses.Address2, TblList_Addresses.Address3, TblList_Addresses.City, TblList_Addresses.State, TblList_Addresses.PostCode, TblList_Addresses.Country, TblList_RecipientDetails.Current, TblList_RecipientDetails.DeativateDate FROM TblList_RecipientDetails INNER JOIN TblList_Addresses ON TblList_RecipientDetails.[Project/OfficeName] = TblList_Addresses.[Project/OfficeName] WHERE ((([TblList_RecipientDetails]![FirstName] & [TblList_RecipientDetails]![Surname]) like '" & Txt_RecipientName & "')));"
Can you explain why in this field name

Expand|Select|Wrap|Line Numbers
  1. TblList_RecipientDetails.[Project/OfficeName] = TblList_Addresses.[Project/OfficeName]
Oct 1 '07 #4
jrtox
89
Hello,

you said that you created a query in Access where you joined 2 fields, Right?

Maybe my step might help.

1.
1.A. You dont need to paste that very long Set of SQL STATEMENT to your VB..
1.B. Just save youre query, example:QUIRYNAME.

2.When youre Using ADODC object then Setup a connection between ur VB and ACCESS.
3.then try the code below
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "SELECT * FROM QUIRYNAME" ' Calls directly to your quiry.
Set DataGrid1.DataSource = Adodc1' Optional

4. if Using ADODB then

dim CONN as NEW ADODB.Connection
dim RS. as NEw ADODB.Recordset

'Establish CONN as A Connection

then,

RS.Open "SELECT * FROM QUIRYNAME",CONN,,
Set Datagrid1.datasource=RS

5. Goodluck!!

Regards
Ervin
Oct 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ben Willcox | last post by:
Hi I am having difficulty writing an SQL query to do what I want: I have 1 table with 2 columns, 'id' and 'name': tbl_names: id name -- ---- 1 Bob 2 Jeff 3 Fred
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
2
by: Shaggy Dragon | last post by:
Hi there, been looking for a solution to this for some time now. I've a UNION query that produces a table called AllSecurities: SELECT SecurityNumber, Book AS AllSecurities FROM Trades UNION...
2
by: Jen Dyer via AccessMonster.com | last post by:
I need to join two fields from the same table into one new field: Field 1 = ProjectName Field 2 = State A co-worker needs the new field to contain the State ie. AZ, and the ProjectName ie....
1
by: Steve C | last post by:
Hi, I'm having problems constructing a nested join. It's quite complex, so here's a simplfied example of the problem. Any thoughts on what I'm doig wrong - or if I've got the whole approach...
3
by: Reader | last post by:
Hello all, I am joining two tables in a query and the output should be all those records where two fields in table1 match two corresponding fields in table2. I joined the tables using both...
4
by: Larry | last post by:
OK, I'm just learning MySQL, or at least trying to. I have a table with data as follows USER FIELDID VALUE 1 1 Bob 1 2 Smith 2 1 John 2 ...
12
by: veaux | last post by:
Question about joins in queries. I have 2 tables with a field called "ID". Table 1 Rec1 = Jan12FredFlintstone Rec2 = Feb01WilmaRubble Table 2 Rec1 = Jan12BarneyRubble Rec2 = Mar03SamSlate
2
by: Neekos | last post by:
Im working on web tool that will allow supervisors to see a list of their agents and their call stats for a call center. I have one main table that holds employee IDs and their supervisor names....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.