Hi
I'm trying to execute the following code:
sSQL = "insert into lkpChanges
(SiteRef,ProjectName,InvestmentType,FieldChanged,P reviousDate,NewDate,ChangeDate,CurrentRelaunch)
" & _
"values (" & sRef & ", """ & pName & """,""" & iType &
""",""" & fChange & """," & IIf(IsNull(pDate), Null, pDate) & "," &
IIf(IsNull(txtFSOS), Null, txtFSOS) & "," & Date & "," &
IIf(IsNull(txtFRelaunch), Null, txtFRelaunch) & ");"
DoCmd.RunSQL sSQL
which evaluates to:
insert into lkpChanges
(SiteRef,ProjectName,InvestmentType,FieldChanged,P reviousDate,NewDate,ChangeDate,CurrentRelaunch)
values (572, "Accrington","New","SOS",,02/01/2008,30/05/2008,);
However, i get the message "Syntax error in Insert Into statement"
I presume this is due to the null dates. Is there anyway around this?
Thanks
Paul 2 7354
You need the text "Null, " in your SQL string:
... & IIf(IsNull(pDate), "Null, ", pDate) & ...
To aid with debugging, try adding:
Debug.Print sSQL
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<pa************@hotmail.comwrote in message
news:64**********************************@56g2000h sm.googlegroups.com...
Hi
I'm trying to execute the following code:
sSQL = "insert into lkpChanges
(SiteRef,ProjectName,InvestmentType,FieldChanged,P reviousDate,NewDate,ChangeDate,CurrentRelaunch)
" & _
"values (" & sRef & ", """ & pName & """,""" & iType &
""",""" & fChange & """," & IIf(IsNull(pDate), Null, pDate) & "," &
IIf(IsNull(txtFSOS), Null, txtFSOS) & "," & Date & "," &
IIf(IsNull(txtFRelaunch), Null, txtFRelaunch) & ");"
DoCmd.RunSQL sSQL
which evaluates to:
insert into lkpChanges
(SiteRef,ProjectName,InvestmentType,FieldChanged,P reviousDate,NewDate,ChangeDate,CurrentRelaunch)
values (572, "Accrington","New","SOS",,02/01/2008,30/05/2008,);
However, i get the message "Syntax error in Insert Into statement"
I presume this is due to the null dates. Is there anyway around this?
Thanks
Paul
On Fri, 30 May 2008 06:22:17 -0700 (PDT), "pa************@hotmail.com"
<pa************@hotmail.comwrote:
>Hi
I'm trying to execute the following code:
sSQL = "insert into lkpChanges (SiteRef,ProjectName,InvestmentType,FieldChanged, PreviousDate,NewDate,ChangeDate,CurrentRelaunch) " & _
"values (" & sRef & ", """ & pName & """,""" & iType & """,""" & fChange & """," & IIf(IsNull(pDate), Null, pDate) & "," & IIf(IsNull(txtFSOS), Null, txtFSOS) & "," & Date & "," & IIf(IsNull(txtFRelaunch), Null, txtFRelaunch) & ");"
DoCmd.RunSQL sSQL
which evaluates to:
insert into lkpChanges (SiteRef,ProjectName,InvestmentType,FieldChanged, PreviousDate,NewDate,ChangeDate,CurrentRelaunch) values (572, "Accrington","New","SOS",,02/01/2008,30/05/2008,);
However, i get the message "Syntax error in Insert Into statement"
I presume this is due to the null dates. Is there anyway around this?
Thanks Paul
You've got a few problems there. Dates need to be quoted with #. You
might have some trouble with your date format. You need placeholders
for the nulls.
>values (572, "Accrington","New","SOS",Null,#02/01/2008#,#30/05/2008#,Null);
or, you might have to change the date format:
>values (572, "Accrington","New","SOS",Null,#01/02/2008#,#05/30/2008#,Null);
should work.
Arch This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Boefje |
last post by:
Hello,
I need to get all records from a table where a for a given playerid no
field enddate exists with value NULL.
table player_team:
id, playerid, startdate, enddate
1, ...
|
by: duikboot |
last post by:
Hi all,
I'm trying to export a view tables from a Oracle database to a Mysql
database. I create insert statements (they look alright), but it all goes
wrong when I try to execute them in Mysql,...
|
by: Jason Tudisco |
last post by:
Hello, I not sure if this is the right place to ask this... I am using
mysql.
What I need is a SQL statement that can find what years are in the
database that is greater than last year.
For...
|
by: php newbie |
last post by:
Hello,
I am trying to insert some date values into a table. I am using ODBC
prepared statements to (potentially) improve performance. The
statement syntax I am using is this:
INSERT INTO...
|
by: iStrain |
last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the
answer in a way I can make sense out of. I know I should get this, but
so far no way...
I'm creating tables and doing queries in...
|
by: Python_it |
last post by:
Python 2.4
MySQL-python.exe-1.2.0.win32-py2.4.zip
How can I insert a NULL value in a table (MySQL-database).
I can't set a var to NULL? Or is there a other possibility?
My var must be variable...
|
by: craigkenisston |
last post by:
I have a generic function that receives a couple of datetime values to
work with. They can or cannot have a value, therefore I wanted to use
null. This function will call a database stored...
|
by: Bob |
last post by:
using "Imports System.Data.odbc", I'm using textbox "text" property to insert a new record into te dataset. If the date textbox is empty the dataset won't accept the value. How do I insert a null...
|
by: teddysnips |
last post by:
I have an application that does some data manipulation of some tables
to format a table for a report.
1. First I open the table that gives me the parameters for some later
queries
strSQL =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
| |