473,804 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Null dates in Insert Into statement

Hi

I'm trying to execute the following code:

sSQL = "insert into lkpChanges
(SiteRef,Projec tName,Investmen tType,FieldChan ged,PreviousDat e,NewDate,Chang eDate,CurrentRe launch)
" & _
"values (" & sRef & ", """ & pName & """,""" & iType &
""",""" & fChange & """," & IIf(IsNull(pDat e), Null, pDate) & "," &
IIf(IsNull(txtF SOS), Null, txtFSOS) & "," & Date & "," &
IIf(IsNull(txtF Relaunch), Null, txtFRelaunch) & ");"

DoCmd.RunSQL sSQL

which evaluates to:

insert into lkpChanges
(SiteRef,Projec tName,Investmen tType,FieldChan ged,PreviousDat e,NewDate,Chang eDate,CurrentRe launch)
values (572, "Accrington","N ew","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 7380
You need the text "Null, " in your SQL string:

... & IIf(IsNull(pDat e), "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.comwro te in message
news:64******** *************** ***********@56g 2000hsm.googleg roups.com...
Hi

I'm trying to execute the following code:

sSQL = "insert into lkpChanges
(SiteRef,Projec tName,Investmen tType,FieldChan ged,PreviousDat e,NewDate,Chang eDate,CurrentRe launch)
" & _
"values (" & sRef & ", """ & pName & """,""" & iType &
""",""" & fChange & """," & IIf(IsNull(pDat e), Null, pDate) & "," &
IIf(IsNull(txtF SOS), Null, txtFSOS) & "," & Date & "," &
IIf(IsNull(txtF Relaunch), Null, txtFRelaunch) & ");"

DoCmd.RunSQL sSQL

which evaluates to:

insert into lkpChanges
(SiteRef,Projec tName,Investmen tType,FieldChan ged,PreviousDat e,NewDate,Chang eDate,CurrentRe launch)
values (572, "Accrington","N ew","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.comwro te:
>Hi

I'm trying to execute the following code:

sSQL = "insert into lkpChanges
(SiteRef,Proje ctName,Investme ntType,FieldCha nged,PreviousDa te,NewDate,Chan geDate,CurrentR elaunch)
" & _
"values (" & sRef & ", """ & pName & """,""" & iType &
""",""" & fChange & """," & IIf(IsNull(pDat e), Null, pDate) & "," &
IIf(IsNull(txt FSOS), Null, txtFSOS) & "," & Date & "," &
IIf(IsNull(txt FRelaunch), Null, txtFRelaunch) & ");"

DoCmd.RunSQL sSQL

which evaluates to:

insert into lkpChanges
(SiteRef,Proje ctName,Investme ntType,FieldCha nged,PreviousDa te,NewDate,Chan geDate,CurrentR elaunch)
values (572, "Accrington","N ew","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","N ew","SOS",Null, #02/01/2008#,#30/05/2008#,Null);
or, you might have to change the date format:
>values (572, "Accrington","N ew","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
3938
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, 277, 2003-09-14 00:00:00, NULL
5
3499
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, because the dates must have quotes on each side. I just don't know how make the dates right. Well I'll just show you the code and some insert statements it generates. Could anyone please help me?
2
26610
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 example... I have a table full of dates ranging from 2001 to 2005..
1
1972
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 date_tests (date_col) VALUES ( CONVERT(DATETIME, ?, 121) ) The table is defined as "CREATE TABLE date_tests (date_col DATETIME)". Then, I call this prepared statement in a loop to insert some date
3
2133
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 Perl, and Nulls have started to bother me greatly. The first issue is, as far as I understand it, a column should be NOT NULL if it is necessary (required) data. Now, if a column doesn't have to be NOT NULL; that is, it's not _required_ data,...
10
52828
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 string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if ....
8
4344
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 procedure and must save either a null or a real date. However, passing a hardcoded "null" to call this function causes a compilation error : cx.cs(136): Argument '16': cannot convert from '<null>' to 'System.DateTime'
2
1759
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 into the dataset field?
2
22396
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 = "SELECT DISTINCT tblMain.MeasureID, MeasureName, CountryName, AxisID FROM tblMain;" Set rstMeasure = CurrentDb.OpenRecordset(strSQL) With rstMeasure
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.