
Access date/time null values
Quote:
> On 20 Jul 2002 19:38:05 +0100, "Adam D. Barratt"
[...]
>>You've given yourself the answer in the subject line. Rather than
>>attempting to set the fields value to " " (how on earth is that supposed
>>to be a valid date?) or "" (it's a date, not a string), set them to
>>NULL. The whole purpose of NULL in database fields is to indiciate the
>>abscense of a value.
[...]
> strSQL = strSQL & "', [CloseDate]='"
> strSQL = strSQL & txtCloseDate.Text
> strSQL = strSQL & "', [CloseTime]='"
> strSQL = strSQL & txtCloseTime.Text
Replace with:
strSQL = strSQL & "', CloseDate=" & IIf( Trim$( txtCloseDate.Text ) _
= "", "NULL", "'" & txtCloseDate.Text & "'" ) & ", CloseTime = " & _
IIf( Trim$( txtCloseTime.Text ) = "", "NULL", "'" & _
txtCloseTime.Text & "'")
In each case, if the textbox is empty, NULL is passed, otherwise the
contents of the textbox are passed surrounded by single quotes.
Quote:
> strSQL = strSQL & "' WHERE [callid]=" & CInt(txtSearchCallID.Text)
^ ^^^^^ ^
Remove the closing single quote there, as it's been dealt with by the
previous line. Remove the CInt() as it's redundant - you're taking a
string, and concatenating it to a second string; converting to and from
an Integer in the process is pointless and unneccessary.
Wherever possible, avoid multiple string concatentations (repeated
strSQL = strSQL &... in your example). They're slower and more expensive
than simply continuing the assignment over multiple lines, as in my
rework above.
I'd also suggest the acquisition of a good database theory book,
together with a VB book. None of the above is particularly complicated,
although it may seem that way to a novice.
hth
Adam
--
"Do not go where the path may lead, go instead where there is no path
and leave a trail."
-- Ralph Waldo Emerson (1803-1882)