dbTalk Databases Forums  

INSERT sql problem !

comp.databases.ms-access comp.databases.ms-access


Discuss INSERT sql problem ! in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Prakash
 
Posts: n/a

Default INSERT sql problem ! - 10-17-2010 , 05:41 AM






I have a form and want to append 3 values into another table using the
following but can't seem to get the right syntax. Could someone please
help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.

Reply With Quote
  #2  
Old   
Bob Quintal
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 05:54 AM






Prakash <simran (AT) omantel (DOT) net.om> wrote in
news:9c4bac4c-46cb-454a-adbe-c144e24d1dce (AT) u24g2000pru (DOT) googlegroups.co
m:

Quote:
I have a form and want to append 3 values into another table using
the following but can't seem to get the right syntax. Could
someone please help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.

SQL cannot see the form so you have to put values not references to
values. Try
values (" & Me.txt_DrNote_No & "," & #me.DrNote_Date# & ","""
me.Cert_No & """)"


--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #3  
Old   
Prakash
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 06:05 AM



On Oct 17, 2:54*pm, Bob Quintal <rquin... (AT) sPAmpatico (DOT) ca> wrote:
Quote:
Prakash <sim... (AT) omantel (DOT) net.om> wrote innews:9c4bac4c-46cb-454a-adbe-c144e24d1dce (AT) u24g2000pru (DOT) googlegroups.co
m:

I have a form and want to append 3 values into another table using
the following but can't seem to get the right syntax. Could
someone please help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values *(Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.

SQL cannot see the form so you have to put values not references to
values. Try
values (" & Me.txt_DrNote_No & "," & #me.DrNote_Date# & ","""
me.Cert_No & """)"

--
Bob Q.
PA is y I've altered my address.
Thx Bob for such a quick response. I'm still getting a syntax error.
Here's my final statement

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (" & Me.txt_DrNote_No & "," & #me.DrNote_Date# & ","""
me.Cert_No & """)"

It says "Compile error expected expression" and highlights the "hash"
symbol just before the date.

Any ideas please ?

Rgds,
Prakash.

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 07:13 AM



Prakash wrote:
Quote:
On Oct 17, 2:54 pm, Bob Quintal <rquin... (AT) sPAmpatico (DOT) ca> wrote:
Prakash <sim... (AT) omantel (DOT) net.om> wrote
innews:9c4bac4c-46cb-454a-adbe-c144e24d1dce (AT) u24g2000pru (DOT) googlegroups.co
m:

I have a form and want to append 3 values into another table using
the following but can't seem to get the right syntax. Could
someone please help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.

SQL cannot see the form so you have to put values not references to
values. Try
values (" & Me.txt_DrNote_No & "," & #me.DrNote_Date# & ","""
me.Cert_No & """)"

--
Bob Q.
PA is y I've altered my address.

Thx Bob for such a quick response. I'm still getting a syntax error.
Here's my final statement

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (" & Me.txt_DrNote_No & "," & #me.DrNote_Date# & ","""
me.Cert_No & """)"

It says "Compile error expected expression" and highlights the "hash"
symbol just before the date.

Here's another reason I switched to using parameters ... but that's another
discussion. :-)

The goal when doing dynamic sql is to create a string that will run as-is
when pasted in the sql view of a query builder window. So, you have to see
the result of your concatenations to see what is going wrong. debug.print is
a great tool. In this case, the line:
debug.print sSQL will allow you to see the sql statement you are attempting
to execute and should allow you to quickly see the error. In this
case,however, the problem is not so simple. The error in this case is
preventing the string from being built. The hash marks have to be part of
the literal string expressions (inside the quotes) in your statement, like
this:

values (" & Me.txt_DrNote_No & ",#" & me.DrNote_Date & "#,"""

Reply With Quote
  #5  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 08:25 AM



Bob had a slight typo in his reply. It should have been

values (" & Me.txt_DrNote_No & ",#" & me.DrNote_Date & "#,"""
me.Cert_No & """)"

That being said, I'd recommend using the following instead, to handle cases
where the user has a non American Short Date format:

values (" & Me.txt_DrNote_No & "," & Format(me.DrNote_Date,
"\#yyyy\-mm\-dd\#") & ","""
me.Cert_No & """)"


"Prakash" <simran (AT) omantel (DOT) net.om> wrote

Quote:
I have a form and want to append 3 values into another table using the
following but can't seem to get the right syntax. Could someone please
help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values (Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.

Reply With Quote
  #6  
Old   
Prakash
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 09:56 AM



On Oct 17, 5:25*pm, "Douglas J Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
Bob had a slight typo in his reply. It should have been

values (" & Me.txt_DrNote_No & ",#" & me.DrNote_Date & "#,"""
me.Cert_No & """)"

That being said, I'd recommend using the following instead, to handle cases
where the user has a non American Short Date format:

values (" & Me.txt_DrNote_No & "," & Format(me.DrNote_Date,
"\#yyyy\-mm\-dd\#") & ","""
me.Cert_No & """)"

"Prakash" <sim... (AT) omantel (DOT) net.om> wrote in message

news:9c4bac4c-46cb-454a-adbe-c144e24d1dce (AT) u24g2000pru (DOT) googlegroups.com...



I have a form and want to append 3 values into another table using the
following but can't seem to get the right syntax. Could someone please
help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values *(Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.- Hide quoted text -

- Show quoted text -
Thanks Douglas! I did encounter Bob's tiny typo but managed to work my
way around it. Many thanks to you Bob ... you were a great help.
Douglas, thanks for pointing out that caveat ... I'll give it a shot.

Once again ... thanks everyone :-)

Rgds,
Prakash.

Reply With Quote
  #7  
Old   
Bob Quintal
 
Posts: n/a

Default Re: INSERT sql problem ! - 10-17-2010 , 02:35 PM



Prakash <simran (AT) omantel (DOT) net.om> wrote in
news:863a2879-4614-4c48-84a1-91ab67e2e77a (AT) o15g2000prh (DOT) googlegroups.co
m:

Quote:
On Oct 17, 5:25*pm, "Douglas J Steele"
NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Bob had a slight typo in his reply. It should have been

values (" & Me.txt_DrNote_No & ",#" & me.DrNote_Date & "#,"""
me.Cert_No & """)"

That being said, I'd recommend using the following instead, to
handle cas
es
where the user has a non American Short Date format:

values (" & Me.txt_DrNote_No & "," & Format(me.DrNote_Date,
"\#yyyy\-mm\-dd\#") & ","""
me.Cert_No & """)"

"Prakash" <sim... (AT) omantel (DOT) net.om> wrote in message

news:9c4bac4c-46cb-454a-adbe-c144e24d1dce (AT) u24g2000pru (DOT) googlegroups
.com...



I have a form and want to append 3 values into another table
using the following but can't seem to get the right syntax.
Could someone please help out ?

sSQL = "INSERT INTO DebitNote (DrNote_No, DrNote_Date, Cert_No)
values *(Me.Txt_DrNote_No, #me.DrNote_Date#, me.Cert_No)"
DoCmd.RunSQL sSQL

DrNote_No is a numeric field
DrNote_Date is a date/time field
Cert_No is a text field

Thanks & Rgds,
Prakash.- Hide quoted text -

- Show quoted text -

Thanks Douglas! I did encounter Bob's tiny typo but managed to
work my way around it. Many thanks to you Bob ... you were a great
help. Douglas, thanks for pointing out that caveat ... I'll give
it a shot.

Once again ... thanks everyone :-)

Rgds,
Prakash.
Glad you got it to work.

Sorry about the typos, It was early morning and I was still half
asleep, or I would have caught and corrected them.

Make that 90% still asleep, I should have caught them at half asleep.

--
Bob Q.
PA is y I've altered my address.

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.