What is wrong with this SQL string?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,

I have a SQL string here that is intended to add the contents of a textbox
into an unrelated table at the click of a button(the table is the rowsource
for the textbox).

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Place.Value
& ");"

When I run this, it brings up a little dialog box asking me for the value of
whatever text I have entered into the textbox.......eg. if I type in ABCD,
it will ask for a value for ABCD. If I enter a value into the text box, it
accepts it and places in the table.

What am I doing wrong?

Thanks guys.

Kenny
 
Hi Kenny,

Try
Me.Place.Value
instead of Place.Value. But IMHO it's usually a good idea to make sure
that controls on forms don't have the same names as the fields they are
bound to. So I'd call the textbox
txtPlace
instead, hence
Me.txtPlace.Value

This assumes that the code is in the same form as the control. For a
control on a different form you can use
Forms("frmName").Controls("txtPlace").Value
or
Forms!frmName!txtPlace



Hi guys,

I have a SQL string here that is intended to add the contents of a textbox
into an unrelated table at the click of a button(the table is the rowsource
for the textbox).

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Place.Value
& ");"

When I run this, it brings up a little dialog box asking me for the value of
whatever text I have entered into the textbox.......eg. if I type in ABCD,
it will ask for a value for ABCD. If I enter a value into the text box, it
accepts it and places in the table.

What am I doing wrong?

Thanks guys.

Kenny
 
Assuming that you're trying to load Text values and not Numeric ones, you
need quotes around your values. Try

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Chr$(34) &
Place.Value & Chr$(34) & ");"

Chr$(34) is the " character.
 
Hi John,

Thanks for the reply.......unfortunately it did not work.

The code is in the same form as the code. Just to be more specific about the
error.......it comes up asking me to enter a parameter value.

Ok.....any other ideas?

Thanks

Kenny

John Nurick said:
Hi Kenny,

Try
Me.Place.Value
instead of Place.Value. But IMHO it's usually a good idea to make sure
that controls on forms don't have the same names as the fields they are
bound to. So I'd call the textbox
txtPlace
instead, hence
Me.txtPlace.Value

This assumes that the code is in the same form as the control. For a
control on a different form you can use
Forms("frmName").Controls("txtPlace").Value
or
Forms!frmName!txtPlace



Hi guys,

I have a SQL string here that is intended to add the contents of a textbox
into an unrelated table at the click of a button(the table is the rowsource
for the textbox).

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Place.Value
& ");"

When I run this, it brings up a little dialog box asking me for the value of
whatever text I have entered into the textbox.......eg. if I type in ABCD,
it will ask for a value for ABCD. If I enter a value into the text box, it
accepts it and places in the table.

What am I doing wrong?

Thanks guys.

Kenny
 
Ok thanks Doug......that did it.

Kenny

Douglas J. Steele said:
Assuming that you're trying to load Text values and not Numeric ones, you
need quotes around your values. Try

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Chr$(34) &
Place.Value & Chr$(34) & ");"

Chr$(34) is the " character.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi guys,

I have a SQL string here that is intended to add the contents of a textbox
into an unrelated table at the click of a button(the table is the rowsource
for the textbox).

DoCmd.RunSQL "INSERT INTO tblLetdownplaces([Place]) VALUES( " & Place.Value
& ");"

When I run this, it brings up a little dialog box asking me for the
value
of
whatever text I have entered into the textbox.......eg. if I type in ABCD,
it will ask for a value for ABCD. If I enter a value into the text box, it
accepts it and places in the table.

What am I doing wrong?

Thanks guys.

Kenny
 
Back
Top