ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA & SQL: INSERT TO... problem with date (https://www.excelbanter.com/excel-programming/335531-vba-sql-insert-problem-date.html)

Santiago[_2_]

VBA & SQL: INSERT TO... problem with date
 
How can I insert a blank field into a date field in Access?

For example, I have a Table with the fields Name, Surname, Birthday(Date).

I'd like to insert a new record based on an excel sheet using ADO & SQL
String. If the birthday field is empty I get an error. The value is ##
because the field is empty.

SQLstring = "INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY) VALUES('Johnny',
'Walker', ##)"

Thanks


Bob Phillips[_7_]

VBA & SQL: INSERT TO... problem with date
 
Presumably the Access table allows nulls for birthday?

If so, just use

SQLstring = "INSERT INTO TABLE(NAME, SURNAME) VALUES('Johnny', 'Walker')"


--
HTH

Bob Phillips

"Santiago" wrote in message
...
How can I insert a blank field into a date field in Access?

For example, I have a Table with the fields Name, Surname, Birthday(Date).

I'd like to insert a new record based on an excel sheet using ADO & SQL
String. If the birthday field is empty I get an error. The value is ##
because the field is empty.

SQLstring = "INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY) VALUES('Johnny',
'Walker', ##)"

Thanks




Santiago[_2_]

VBA & SQL: INSERT TO... problem with date
 
Thanks Bob,

the problem is that this code is in the middle of other code, so I should
check if the field is empty or not, etc...

is there any way to insert a Null value? For Text or number you just put two
single quotes ('') and that's it. For dates?

Thanks.

"Bob Phillips" wrote:

Presumably the Access table allows nulls for birthday?

If so, just use

SQLstring = "INSERT INTO TABLE(NAME, SURNAME) VALUES('Johnny', 'Walker')"


--
HTH

Bob Phillips

"Santiago" wrote in message
...
How can I insert a blank field into a date field in Access?

For example, I have a Table with the fields Name, Surname, Birthday(Date).

I'd like to insert a new record based on an excel sheet using ADO & SQL
String. If the birthday field is empty I get an error. The value is ##
because the field is empty.

SQLstring = "INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY) VALUES('Johnny',
'Walker', ##)"

Thanks





keepITcool

VBA & SQL: INSERT TO... problem with date
 

use the Null keyword.


"INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY)
VALUES('Johnny', 'Walker', Null)"



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Santiago wrote :

How can I insert a blank field into a date field in Access?

For example, I have a Table with the fields Name, Surname,
Birthday(Date).

I'd like to insert a new record based on an excel sheet using ADO &
SQL String. If the birthday field is empty I get an error. The value
is ## because the field is empty.

SQLstring = "INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY)
VALUES('Johnny', 'Walker', ##)"

Thanks


Santiago[_2_]

VBA & SQL: INSERT TO... problem with date
 
Thanks KIC, I believe I tried that and did not work, but maybe the problem
was another one. For "UPDATE" SQL command Null seems to work, so should also
work for "INSERT INTO" command.

I'll try again and recheck. Thanks

"keepITcool" wrote:


use the Null keyword.


"INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY)
VALUES('Johnny', 'Walker', Null)"



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Santiago wrote :

How can I insert a blank field into a date field in Access?

For example, I have a Table with the fields Name, Surname,
Birthday(Date).

I'd like to insert a new record based on an excel sheet using ADO &
SQL String. If the birthday field is empty I get an error. The value
is ## because the field is empty.

SQLstring = "INSERT INTO TABLE(NAME, SURNAME, BIRTHDAY)
VALUES('Johnny', 'Walker', ##)"

Thanks




All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com