Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2004, 07:32 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting/updating with empty date field

I am posting data from a form into an Access database in ASP, inserting or updating records. Several of the fields in the table are date fields. The form data may include a date in one or more of those fields, or one or more may be left empty. How can I develop a variable that will post whether containing a date or Null, so that I can use the construction datefield=#" & variable & "#? Or is there some other way to accomplish this?

 
Old December 23rd, 2004, 05:25 AM
Authorized User
 
Join Date: Sep 2004
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to nashnash
Default


Function CheckDate(strDate)
    IF IsDate(strDate)Then
        CheckDate= strDate
    ELSE
        CheckDate= NULL
    END IF

End Function

----call this as ----

CheckDate(strDate)


Thanks
Nash


 
Old December 23rd, 2004, 05:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

If you change Nash's function slightly, you can call it as described...

Code:
Function CheckDate(strDate)
    IF IsDate(strDate)Then
        CheckDate= "'#" & strDate & "#'"
    ELSE
        CheckDate= NULL
    END IF     
End Function
strSQL = "... datefield = " & CheckDate(dtDateVar)

 
Old December 23rd, 2004, 02:14 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. With some modification, the method you suggested worked.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on updating the date field surya MySQL 2 September 16th, 2008 11:56 PM
inserting and updating records in classic asp codetoad Classic ASP Databases 2 March 21st, 2007 07:40 AM
Updating a Date field based on another field arholly Access VBA 6 November 22nd, 2006 11:19 AM
Empty record field, No image dstubblefield Dreamweaver (all versions) 6 September 3rd, 2004 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.