deleting date data

jar
12-05-2000, 12:24 AM
How do you delete date data? That is, suppose you have a database with a date field. The date field is in a client record and indicates when the user wants to contact the client. The user enters a date into a record. Later, the user would need to delete the date when they no longer need to schedule a call.

I would like to delete the date by programming; assigning a null value to the date field. I get an error message. Assigning a zero-length strings also produces errors since strings cannot be entered into the date.

I could just copy the whole record into another record except for the date field. However, I was hoping there was a more direct way of doing this.

PWNettle
12-05-2000, 08:34 AM
If you're using Access (97, should work with 2000 too) or SQL server you should be able to NULL your date fields. One way is to do it with a SQL statement on your connection object:
<PRE>conYourConnectionObject.Execute "UPDATE YourTableName SET YourDateField=NULL" WHERE YourPrimaryKeyField=" & PrimaryKeyValueToBeAffected</PRE>You could probably do this in a recordset if you set the field to NULL inside a string like so:
<PRE> rstYourRecordset.Fields("YourDateField") = "NULL"</PRE>
Cheers,
Paul

jar
12-08-2000, 04:03 PM
Thank you for your suggestion. I couldn't get it to work with my set up. I have a text box bound to a date field using a datacontrol. I don't think a date field will accept a Null.

However, I did find a solution by trial and error. What I did was to set the date field to "Empty" in the underlying database.

dtaDatabase1.recordset.datefield = "Empty"

This is a method I haven't found in the MS VB 5 online help or my reference books. I had a hard time figuring it out because I was trying to set the bound text box to "Empty," which it apparently doesn't accept.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum