473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Null dates in Insert Into statement

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
Jun 27 '08 #1
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
Jun 27 '08 #2
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
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
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, ...
5
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,...
2
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...
1
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...
3
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...
10
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...
8
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...
2
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...
2
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 =...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.