Insert Into Query

G

Guest

I created a team nomination form with 3 command buttons, if users click on
any of the button I want the team member information to be inserted into
another table. I used the following code:


Dim SQL As String
Dim strWhere As String

strWhere = Me.Contact_LastName

SQL = "INSERT INTO tblteams " & _
"(teamname) " & _
"SELECT Contact_LastName FROM Results Where =" & strWhere & "'"

DoCmd.RunSQL SQL

But there is an error in the Where clause, can someone help me please?

Thanks
 
G

Guest

You are probably missing the " " around the name. Try
.....Results Where =""" & strWhere & "'"

NevilleT
 
G

Guest

My guess is that this should do the trick as well:

"SELECT Contact_LastName FROM Results Where = '" & strWhere & "'"

(just a single quote before the double quote before the ampersand)
 
G

Guest

And you should apply your field name as well on what the criteria field is.

"SELECT Contact_LastName FROM Results Where [yourfield] ='" & strWhere & "'"
 
D

Douglas J. Steele

Of course, that's still missing the field name to which the value is being
compared (and it won't work if strWhere contains an apostrophe)
 
G

Guest

Thanks guys
--
TO


Maurice said:
And you should apply your field name as well on what the criteria field is.

"SELECT Contact_LastName FROM Results Where [yourfield] ='" & strWhere & "'"
--
Maurice Ausum


NevilleT said:
You are probably missing the " " around the name. Try
....Results Where =""" & strWhere & "'"

NevilleT
 

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

Top