Solved

Clearing a date field

Posted on 2004-10-20
3
144 Views
Last Modified: 2012-05-05
Greetings, all,

Using an SQL database, I am having trouble clearing a datefield.  If I highlight and delete the existing date, I get an Invalid Date Format error.

I have tried doing it in code by making it    = ""  and also trying   = NULL   and   = <NULL>  but nothing seems to work.

My son-in-law reckons the best way to do it is to store it in a text field, but I'm sure there is a (very) simple answer . . .   o:}

Regards
Tony
0
Comment
Question by:pitwood
3 Comments
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 12363182
Are you trying to do this from code or from the database?

Using Enterprise Manager for SQL Server, you can press Ctrl+0.
That will set the field to Null.
0
 
LVL 6

Accepted Solution

by:
PePi earned 125 total points
ID: 12363296
does the date field allow nulls?

if so,  a simple update statement can clear the field.

e.g.

update your_table set date_field = Null

0
 

Author Comment

by:pitwood
ID: 12372801
Hi PePi

Thanks for your answer - it works well in code as in this example  

    If Len(fg2.TextMatrix(fg2.Row, 2)) < 1 Then
       DataEnvironment1.rsBldRemarks!DateDue = Null
    Else
       DataEnvironment1.rsBldRemarks!DateDue = fg2.TextMatrix(fg2.Row, 2)
    End If


but if I try to change a text box linked to the database as follows, it doesn't work too well

 Private Sub Text10_LostFocus()
  On Error GoTo ten
  If Len(Text10) = 0 Then datPrimaryRS.Recordset!VacatingDate = Null
Exit Sub

ten:
  Debug.Print Err, Err.Description
End Sub

This appears to work OK but when I hit the command

 datPrimaryRS.Recordset.Update

it comes back with "MultiStep operation generated errors.

This is what I'm battling with.

Regards
Tony

P.S. Maybe I should raise it as another question as I have already awarded the points?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question