Vba to insert null into date field (1 Viewer)

Margarita

Registered User.
Local time
Today, 18:28
Joined
Aug 12, 2011
Messages
185
Hello,
How does one handle an insert statement in vba in which some fields (values coming from unbound textboxes) may or may not be blank? Specifically, the problem is with date fields which are not required and may therefore be left blank by the user.

I did an extensive search, but all the articles and threads I found seem to resolve in a manner similar to this thread:
http://www.access-programmers.co.uk/forums/showthread.php?t=114920
where the author claims the problem was resolved by using a statement like:
Datetoinsert = IIf(IsNull(Me.txtDate), vbNull, Me.txtDate)

This does NOT work. Neither does replacing vbNull with Null or ''. I still get an error that fails when it thinks the insert statement is trying to insert ##.
Does anyone know a solution to this that actually works?

Thank you.
 

mdlueck

Sr. Application Developer
Local time
Today, 18:28
Joined
Jun 23, 2011
Messages
2,631
In my VBA classes I treat date database fields as a string.

To perform a save to the database, using ADO.Command / ADO.Parameters objects, I use the following code:

Code:
    .Parameters("@quotedate").Type = adDBTimeStamp
    If Me.quotedate = vbNullString Then
      .Parameters("@quotedate").Value = Empty
    Else
      .Parameters("@quotedate").Value = Me.quotedate
    End If
* This works if the field in the table is not a required field.
 

Users who are viewing this thread

Top Bottom