Syntax Error in INSERT INTO Statement

M

Mark

Hi -

Access returns a "Syntax Error in INSERT INTO Statement" when the date field
contains a Null value.

Code:

strSQL = "Insert Into MyTable Values ( _
Chr$(34) & strName & Chr$(34) & ", " & _
Chr$(35) & datDOB & Chr$(35) & ", " & _
Chr$(34) & strState & Chr$(34) & ")

myDB.Execute strSQL

When datDOB is Null, Access returns the error.

Any way to make the statement work with a Null Date value?

Thanks,
MArk
 
A

Allen Browne

You need the word Null to appear in the query string when datDOB is null.

strSql = "INSERT INTO MyTable Values (""" & strName & """, " & _
IIf(IsNull(datDOB), "Null", "#" & datDOB & "#") & ", """ & strState &
""");"
 
M

Mark

Allen -

Thank you much!!!

Allen Browne said:
You need the word Null to appear in the query string when datDOB is null.

strSql = "INSERT INTO MyTable Values (""" & strName & """, " & _
IIf(IsNull(datDOB), "Null", "#" & datDOB & "#") & ", """ & strState &
""");"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top