Insert Into Syntax error

  • Thread starter Thread starter peashoe
  • Start date Start date
P

peashoe

can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName, [School
Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa
 
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
 
Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk said:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Did you type it exactly as Dirk did? The reason Dirk typed it that way was
to ensure that you don't run into any problems with word-wrap in your
newsreader. Make sure you have a space in front of each underscore. This
presupposes that [School Or Organization ID] is a numeric field, that the
Registrations form is open (and has a value in txtID) when you're running
the code, and that Team.Value is a valid reference (what is it supposed to
be?).

The problem with what you had was a combination of incorrect parentheses
(the opening one after CurrentDb.Execute) and incorrect quotes.

If you still can't get it, try:

Dim strSQL As String

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
Debug.Print strSQL
CurrentDb.Execute strSQL

Look in the Immediate Window (Ctrl-G). What's printed there for strSQL?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk said:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
yes I typed it in exactly as you had it and the entire thing is red
from StrSQL = _ to ")" When I try to run it - it just says Syntax
error. [School or Organization ID] is a number, reg form was open (im
adding this in the onchange event of Team textbox) and txtID is
autopopulate with the registration form

~L~
Did you type it exactly as Dirk did? The reason Dirk typed it that way was
to ensure that you don't run into any problems with word-wrap in your
newsreader. Make sure you have a space in front of each underscore. This
presupposes that [School Or Organization ID] is a numeric field, that the
Registrations form is open (and has a value in txtID) when you're running
the code, and that Team.Value is a valid reference (what is it supposed to
be?).

The problem with what you had was a combination of incorrect parentheses
(the opening one after CurrentDb.Execute) and incorrect quotes.

If you still can't get it, try:

Dim strSQL As String

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
Debug.Print strSQL
CurrentDb.Execute strSQL

Look in the Immediate Window (Ctrl-G). What's printed there for strSQL?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk said:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Hold on. Another typo (and I'm going to pin blame for this one on Dirk! <g>)
The quotes were still wrong. Try:

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' , " & _
[Forms]![Registrations]![txtID] & _
")"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


yes I typed it in exactly as you had it and the entire thing is red
from StrSQL = _ to ")" When I try to run it - it just says Syntax
error. [School or Organization ID] is a number, reg form was open (im
adding this in the onchange event of Team textbox) and txtID is
autopopulate with the registration form

~L~
Did you type it exactly as Dirk did? The reason Dirk typed it that way
was
to ensure that you don't run into any problems with word-wrap in your
newsreader. Make sure you have a space in front of each underscore. This
presupposes that [School Or Organization ID] is a numeric field, that the
Registrations form is open (and has a value in txtID) when you're running
the code, and that Team.Value is a valid reference (what is it supposed
to
be?).

The problem with what you had was a combination of incorrect parentheses
(the opening one after CurrentDb.Execute) and incorrect quotes.

If you still can't get it, try:

Dim strSQL As String

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
Debug.Print strSQL
CurrentDb.Execute strSQL

Look in the Immediate Window (Ctrl-G). What's printed there for strSQL?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk Goldgar wrote:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Doug nope that didn't work - but I got it:

CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName, [School Or
Organization ID]) VALUES ('" & Team.Value & "'" & ", '" &
[Forms]![Registrations]![txtID] & "')")

Thanks guys for yout help
~L~

Hold on. Another typo (and I'm going to pin blame for this one on Dirk! <g>)
The quotes were still wrong. Try:

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' , " & _
[Forms]![Registrations]![txtID] & _
")"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


yes I typed it in exactly as you had it and the entire thing is red
from StrSQL = _ to ")" When I try to run it - it just says Syntax
error. [School or Organization ID] is a number, reg form was open (im
adding this in the onchange event of Team textbox) and txtID is
autopopulate with the registration form

~L~
Did you type it exactly as Dirk did? The reason Dirk typed it that way
was
to ensure that you don't run into any problems with word-wrap in your
newsreader. Make sure you have a space in front of each underscore. This
presupposes that [School Or Organization ID] is a numeric field, that the
Registrations form is open (and has a value in txtID) when you're running
the code, and that Team.Value is a valid reference (what is it supposed
to
be?).

The problem with what you had was a combination of incorrect parentheses
(the opening one after CurrentDb.Execute) and incorrect quotes.

If you still can't get it, try:

Dim strSQL As String

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
Debug.Print strSQL
CurrentDb.Execute strSQL

Look in the Immediate Window (Ctrl-G). What's printed there for strSQL?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk Goldgar wrote:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", " &
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
You said [School or Organization ID] is numeric, yet you've got quotes
around the value in your final answer!

No wonder ours didn't work...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Doug nope that didn't work - but I got it:

CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName, [School Or
Organization ID]) VALUES ('" & Team.Value & "'" & ", '" &
[Forms]![Registrations]![txtID] & "')")

Thanks guys for yout help
~L~

Hold on. Another typo (and I'm going to pin blame for this one on Dirk!
<g>)
The quotes were still wrong. Try:

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' , " & _
[Forms]![Registrations]![txtID] & _
")"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


yes I typed it in exactly as you had it and the entire thing is red
from StrSQL = _ to ")" When I try to run it - it just says Syntax
error. [School or Organization ID] is a number, reg form was open (im
adding this in the onchange event of Team textbox) and txtID is
autopopulate with the registration form

~L~

Douglas J. Steele wrote:
Did you type it exactly as Dirk did? The reason Dirk typed it that way
was
to ensure that you don't run into any problems with word-wrap in your
newsreader. Make sure you have a space in front of each underscore.
This
presupposes that [School Or Organization ID] is a numeric field, that
the
Registrations form is open (and has a value in txtID) when you're
running
the code, and that Team.Value is a valid reference (what is it
supposed
to
be?).

The problem with what you had was a combination of incorrect
parentheses
(the opening one after CurrentDb.Execute) and incorrect quotes.

If you still can't get it, try:

Dim strSQL As String

strSQL = _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"
Debug.Print strSQL
CurrentDb.Execute strSQL

Look in the Immediate Window (Ctrl-G). What's printed there for
strSQL?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dirk,
Tried that it didn't work - can you try it in one line like I had at
the top?
~L~

Dirk Goldgar wrote:
can anyone please tell me what's wrong with this statement?
CurrentDb.Execute ("INSERT INTO TeamMascot (TeamMascotName,
[School Or Organization ID]) VALUES ('" & Team.Value & "' & ", "
&
[Forms]![Registrations]![txtID])")

I'm getting a syntax error. I tried
[Forms]![Registrations]![txtID].Value and that doesn't work
either?

Thanks in advance
Lisa

Looks like you're missing one quote. Try this:

CurrentDb.Execute _
"INSERT INTO TeamMascot " & _
"(TeamMascotName, [School Or Organization ID]) " & _
"VALUES ('" & _
Team.Value & "' & ", " & _
[Forms]![Registrations]![txtID] & _
")"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top