
Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
We only have a Current event that is suppose to execute only when there are
values in 2 of the txt boxes, see below
Private Sub Form_Current()
If Me.Date_Invoice_Received_In_A_P.Value <> "" And
Me.Date_Invoice_Received_In_Market.Value <> "" Then
Me.Days_to_Market.Value = DateDiff("d",
Me.Date_Invoice_Received_In_A_P.Value,
Me.Date_Invoice_Received_In_Market.Value)
Else
Me.Days_to_Market.Value = 0
End If
End Sub
This is the code that opens the form from the main form:
Private Sub CreateNewInvoice_Click()
DoCmd.Close acForm, "Invoice Database Launch", acSaveYes
DoCmd.OpenForm "Invoice Tracker New Entry", acNormal
Application.Forms("Invoice Tracker New Entry").Caption = "CREATE INVOICE"
DoCmd.GoToRecord , , acNewRec
End Sub
> > We are have a somewhat of an annoying problem with one of our database
> > forms.
[quoted text clipped - 20 lines]
> the normal "blank" record for additions that is being displayed? When you
> look directly in the table, do you see these records?
Pat Hartman - 21 Jan 2008 15:18 GMT
"" is a zero-length-string (ZLS) which is NOT the same as a null. Dates are
numeric values and therefore NOT strings. To determine if a date is empty,
use the IsNull() function rather than comparing to ""
If Not IsNull(Me.Date_Invoice_Received_In_A_P.Value) And
> Not IsNull(Me.Date_Invoice_Received_In_Market.Value) Then
Another useful date function is IsDate() which in this case will allow you
to make a positive rather than a negative comparison.
If IsDate(Me.Date_Invoice_Received_In_A_P.Value) And
> IsDate(Me.Date_Invoice_Received_In_Market.Value) Then
> We only have a Current event that is suppose to execute only when there
> are
[quoted text clipped - 47 lines]
>> you
>> look directly in the table, do you see these records?
Ayo - 21 Jan 2008 15:44 GMT
Thanks pat for the correction. But my problem still persist.
> "" is a zero-length-string (ZLS) which is NOT the same as a null. Dates are
> numeric values and therefore NOT strings. To determine if a date is empty,
[quoted text clipped - 60 lines]
> >> you
> >> look directly in the table, do you see these records?
Dirk Goldgar - 21 Jan 2008 15:41 GMT
> We only have a Current event that is suppose to execute only when there
> are
[quoted text clipped - 9 lines]
> End If
> End Sub
Yes, that would do it, all right. Every time you arrive at a new record,
you set the value of Days_to_Market, either to a value calculated from the
other text boxes, or to zero. That will happen whether you are on a blank
new record, or on an existing record.
At the very least, you should fix the date tests to check for Null rather
than "", and you should drop the Else clause that sets Days_to_Market to
zero. How about this:
If Not IsNull(Me.Date_Invoice_Received_In_A_P) _
And Not IsNull(Me.Date_Invoice_Received_In_Market) _
Then
Me.Days_to_Market = _
DateDiff("d", _
Me.Date_Invoice_Received_In_A_P,
Me.Date_Invoice_Received_In_Market)
End If
I would leave Days_to_Market as Null when either of those base dates is
unknown; however, you could have it *default* to zero by setting it's
Default Value property to 0.
But aside from all that, this looks a whole lot like storing a calculated
value. Is it possible for the value of Days_to_Market ever to have a value
that is *different* from the number of days between those two dates? If
not, there is not reason ever to store it, and several good reasons not to
(efficiency, reliability). So in all probability, you should just define
this as a calculated field, either in the text box's controlsource or as a
calculated field in the form's recordsource query. If you do it as a
calculated control, the controlsource would be:
=DateDiff("d", [Date_Invoice_Received_In_A_P],
[Date_Invoice_Received_In_Market])
As a calculated field in the query, you might enter something like this in
the query design grid:
Days_to_Market: DateDiff("d", Date_Invoice_Received_In_A_P,
Date_Invoice_Received_In_Market)
Note that both of the above expressions will have been broken onto two lines
by the newsreader, but they are intended each to be on a single line.

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
Yes. The form creates a new blank record everytime you close it, even if all
the txt boxes and combo boxes are blank.
> > We are have a somewhat of an annoying problem with one of our database
> > forms.
[quoted text clipped - 20 lines]
> the normal "blank" record for additions that is being displayed? When you
> look directly in the table, do you see these records?