Solved

Clearing a date field

Posted on 2004-10-20
3
141 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now