I have tried this every which way, but if I try to enter a Null, "", vbNullstring, Empty or vbNull into a date field I get an error. There must be a way of setting a date field so it has nothing in it in code, but it eludes me. I can delete the values manually and don't get an error.
Any ideas anyone?
Enter Null into a date field
-
- 5StarLounger
- Posts: 962
- Joined: 09 Feb 2010, 00:33
- Location: Patterson Lakes, Victoria, Australia
Enter Null into a date field
Avagr8day, regards, Peter
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Enter Null into a date field
What happens if you just use: Me.EventDate=Null ?
Works for me.
Works for me.
Regards
John
John
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Enter Null into a date field
In an update query, you should use Null in the Update to: row, and in VBA, you should be able to use code such as
Me.SpecialDate = Null
To make sure, I have tested both just now; they did what was expected without error.
This won't work if the date field is required of course.
Me.SpecialDate = Null
To make sure, I have tested both just now; they did what was expected without error.
This won't work if the date field is required of course.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 962
- Joined: 09 Feb 2010, 00:33
- Location: Patterson Lakes, Victoria, Australia
Re: Enter Null into a date field
Can't get that far.
Dim TargetDateIn As Date
TargetDateIn = Null
gives error:
Invalid use of Null
I tried using DtIn dimmed as variant, then testing if IsNull(DtIn) and if so setting the date field to Null.
It works.
Dim TargetDateIn As Date
TargetDateIn = Null
gives error:
Invalid use of Null
I tried using DtIn dimmed as variant, then testing if IsNull(DtIn) and if so setting the date field to Null.
It works.
Last edited by Peter Kinross on 23 Aug 2017, 07:13, edited 1 time in total.
Avagr8day, regards, Peter
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Enter Null into a date field
You are trying to set a variable to Null rather than a field.
Only variables of type Variant can be Null.
Only variables of type Variant can be Null.
Regards
John
John
-
- 5StarLounger
- Posts: 962
- Joined: 09 Feb 2010, 00:33
- Location: Patterson Lakes, Victoria, Australia
Re: Enter Null into a date field
Thanks John. You were answering and I was editing at the same time.
Avagr8day, regards, Peter
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Enter Null into a date field
Keep in mind that TargetDateIn is a variable, not a field.
Best wishes,
Hans
Hans