Double Quotes and SQL

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I'm trying to change the RowSource of a combo box on the OnLoad event. I
need to concatenate the "userLast" and "userFirst" fields into "userName" as
seen in my code below.

How do I deal with the needed quotes that combine the "userLast" and
"userFirst" fields? Can someone correct my concatenation double quotes
below?

CODE ****************

sSQL = "SELECT userID, [userLast] & "", "" & [userFirst] AS userName" &
_
" FROM t_users"

Me.cboFind.RowSource = sSQL
 
I usually use ' character within a string like this:

sSQL = "SELECT userID, [userLast] & ', ' & [userFirst] AS userName" & _
" FROM t_users"

Otherwise, doubling up the " character should work, which is how you posted
the string. What you posted should work as well.

Is what you posted not working?
 
Hi Scott.
I'm assuming [userLast] and [UserFirst] are two controls on your form.

Try this out:
dim sUser as string
dim sSQL as string

sUser = me![userLast] & me![userFirst]
sSQL = "SELECT userID, " & sUser & " AS userName FROM t_users;"

Hope that helped.
Cheers
Dave
 
Scott,
Where are the userFirst and userLast values coming from? An open form? You
may need to reference the form explicitly first. Try this: (watch out for
word wrapping)

Dim sUser as string
Dim sSQL as string

sUser = me![NameOfYourForm]![userLast] & ", " &
me![NameOfYourForm]![userFirst]

sSQL = "SELECT userID, " & sUser & " AS userName FROM t_users;"

me.recordsource = sSQL

Hope that helped.
Dave
 
No, userFirst and userLast are fields in my table. I've got to be able to
include both of them within the sql statement to get the full name variable
called "userName".


Dave said:
Hi Scott.
I'm assuming [userLast] and [UserFirst] are two controls on your form.

Try this out:
dim sUser as string
dim sSQL as string

sUser = me![userLast] & me![userFirst]
sSQL = "SELECT userID, " & sUser & " AS userName FROM t_users;"

Hope that helped.
Cheers
Dave

Scott said:
I'm trying to change the RowSource of a combo box on the OnLoad event. I
need to concatenate the "userLast" and "userFirst" fields into "userName"
as
seen in my code below.

How do I deal with the needed quotes that combine the "userLast" and
"userFirst" fields? Can someone correct my concatenation double quotes
below?

CODE ****************

sSQL = "SELECT userID, [userLast] & "", "" & [userFirst] AS userName"
&
_
" FROM t_users"

Me.cboFind.RowSource = sSQL
 
i got it using single quotes, thanks.

Dave said:
Scott,
Where are the userFirst and userLast values coming from? An open form? You
may need to reference the form explicitly first. Try this: (watch out for
word wrapping)

Dim sUser as string
Dim sSQL as string

sUser = me![NameOfYourForm]![userLast] & ", " &
me![NameOfYourForm]![userFirst]

sSQL = "SELECT userID, " & sUser & " AS userName FROM t_users;"

me.recordsource = sSQL

Hope that helped.
Dave

Scott said:
I'm trying to change the RowSource of a combo box on the OnLoad event. I
need to concatenate the "userLast" and "userFirst" fields into "userName"
as
seen in my code below.

How do I deal with the needed quotes that combine the "userLast" and
"userFirst" fields? Can someone correct my concatenation double quotes
below?

CODE ****************

sSQL = "SELECT userID, [userLast] & "", "" & [userFirst] AS userName"
&
_
" FROM t_users"

Me.cboFind.RowSource = sSQL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL Quotes 4
concatenating problem 2
Dynamic listbox SQL code 12
Select statement 2
Invalid SQL Statement 9
form combo box displayed record 12
SQL code to insert data from one table into another 5
SQL Quotes 7

Back
Top