Solved

Clearing a date field

Posted on 2004-10-20
3
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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