A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

What is wrong with this SQL string?



 
 
Thread Tools Display Modes
  #1  
Old August 1st, 2004, 07:13 AM
external usenet poster
 
Posts: n/a
Default What is wrong with this SQL string?

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


  #2  
Old August 1st, 2004, 07:47 AM
John Nurick
external usenet poster
 
Posts: n/a
Default What is wrong with this SQL string?

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



On Sun, 1 Aug 2004 08:13:41 +0200, Kenny wrote:

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


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
  #3  
Old August 1st, 2004, 11:55 AM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default What is wrong with this SQL string?

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
http://I.Am/DougSteele
(no e-mails, please!)



Kenny wrote in message ...
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




  #4  
Old August 1st, 2004, 01:39 PM
external usenet poster
 
Posts: n/a
Default What is wrong with this SQL string?

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" wrote in message
...
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



On Sun, 1 Aug 2004 08:13:41 +0200, Kenny wrote:

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


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.



  #5  
Old August 1st, 2004, 01:51 PM
external usenet poster
 
Posts: n/a
Default What is wrong with this SQL string?

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

Kenny

"Douglas J. Steele" wrote in message
...
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
http://I.Am/DougSteele
(no e-mails, please!)



Kenny wrote in message ...
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






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Function isn't available in expressions in query expression Reiner Harmgardt General Discussion 4 July 21st, 2004 09:30 AM
SQL string problem Gary D. Running & Setting Up Queries 6 June 7th, 2004 04:02 PM
SQL string problem Gary D. Using Forms 0 June 1st, 2004 08:45 PM
Question re MailMerge and VB.NET thecoiman Mailmerge 5 May 17th, 2004 04:13 PM


All times are GMT +1. The time now is 12:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.