Hi.
I am trying to execute the following SQL statement, but I'm getting a syntax error - Dim strSQL As String
-
-
strSQL = "INSERT INTO usr_problem_list "
-
strSQL = strSQL & "(trouble_no, date, user, notes) "
-
strSQL = strSQL & "VALUES (" & Text30.Value & ", '" & Now() & "', '" & user_name & "', '" & txtNotes & "');"
-
-
DoCmd.RunSQL strSQL
trouble_no is a number field
date is a date/time field
user is a text field
notes is a memo field
thanks!
Use brackets (Actually - better not to use reserved words at all where possible) around it.
EG. [Date] .
11 4184
ok after playing around with it, the culprit seems to be the "date" bc it's a reserved word?
is there any way around this?
thanks!
NeoPa 32,556
Expert Mod 16PB
Use brackets (Actually - better not to use reserved words at all where possible) around it.
EG. [Date] .
@NeoPa:
thanks for the reply. I'll have to test that out when im at work.
I tried doing table.column, but no luck.
The only other way would be to rename it to something else, but not sure where else the table is used in VBA. so it might create problems, which I definitely do not want that to happen :)
NeoPa 32,556
Expert Mod 16PB
Normally Table.Date would work reliably, I'm not so sure for the syntax here though. The parentheses enclose a field list specifically. IE. A list of field names rather than references to fields.
The brackets [] are also useful for specifying names which include spaces, as SQL typically treats spaces (and any white-space) as separators (but not when they're within brackets of course).
- "INSERT INTO usr_problem_list(trouble_no, date, user, notes)VALUES(" & Text30.Value & ",'" & Format(System.DateTime.Today.Date, "MM/dd/yyyy") & "', '" & user_name & "', '" & txtNotes & "')"
The Sql Server save Date in above format so use this and he datatype in DB should be Datetime. Try above query
NeoPa 32,556
Expert Mod 16PB
I think you misunderstand Monty. The problem is not with the use of the Date() function (and certainly not with Now() - however inappropriate this *might* be). The problem is with the use of the word 'Date' to name the field in the record.
Dear NeoPa i Checked the Date Keyword in my Sql server DB but it's not showing anytype of error as you said Date is reserved keyword. I m using the below query for Checking. - clsobjact.InsertData("insert into Customer(Date)values('" & Format(System.DateTime.Today.Date, "MM/dd/yyyy") & "')")
@Monty - Dim strSQL As String
-
-
strSQL = "INSERT INTO usr_problem_list "
-
strSQL = strSQL & "(trouble_no, [date], [user], notes) "
-
strSQL = strSQL & "VALUES (" & Text30.Value & ", '" & Now() & "', '" & user_name & "', '" & txtNotes & "');"
-
-
DoCmd.RunSQL strSQL
-
Look at line 4, field date and user between square brackets. As NeoPa mentionned, date is a field name to avoid. As far as user go, it is a DAO object. I am a little bit surprised, but in my case, it would not work unless I used square brackets.
NeoPa 32,556
Expert Mod 16PB
Monty, you seem to be under the impression that we are in the SQL Server forum. This forum is for Access / VBA.
In Access, there is a function called Date() which is not only available within VBA, but also within the Jet SQL engine. Hence, a reference to Date within Jet SQL (The native SQL engine of MS Access), without the clarification of the brackets around it (as in [Date]) would be likely to be misconstrued. On the other hand of course, with the brackets the problem disappears. A fairly convincing confirmation that this identifies the problem correctly I would think.
PS. Please remember in future to post all your code in [ CODE ] tags as the site rules require.
ok looks like putting [ ] around date fixed the problem!
that was easy!
thanks everyone for the help.
NeoPa 32,556
Expert Mod 16PB
It's an important thing to learn, even if it seems relatively small :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kosta |
last post by:
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double...
|
by: Tim::.. |
last post by:
Can someone please tell me why I keep getting the following error from the
code below!
Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
|
by: jinhy82 |
last post by:
Hi! I am currently creating a Registration form which contained: UserID
Password, FirstName and LastName.
These details would be inserted into Ms Access when I click submi
button. But I...
|
by: Nathan Sokalski |
last post by:
When trying to submit data to an Access database using ASP.NET I recieve the
following error:
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
+41...
|
by: amitbadgi |
last post by:
Hi guys, I am getting the following error in teh insert statement , I
am converting this asp application to asp.net, here is teh error,
Exception Details:...
|
by: Geoffrey KRETZ |
last post by:
Hello,
I'm wondering if the following behaviour is the correct one for
PostGreSQL (7.4 on UNIX).
I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :...
|
by: vasanth chandrasekaran |
last post by:
The error is :Syntax error in INSERT INTO statement.
This is my code:
try
{
DataSet ds1;
OleDbConnection ConnSql;
OleDbConnection...
|
by: Ed Pisa |
last post by:
Hello,
I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
|
by: Ed Pisa |
last post by:
Hello,
I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |