Re: Earliest Date

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Randal (rlwnr_at_hotmail.com)
Date: 02/03/04


Date: Tue, 3 Feb 2004 11:09:15 -0500

I must have something wrong because I always get zero. I copied the VBA
function into a module just as you have it below. Here is the query I used
to test. There are no null values.

SELECT Least([RptDate]![RptBegin],[RptDate]![RptEnd]) AS SmallestDate1
FROM RptDate;

Once it works, I think I still have a problem that Nz won't help, because
the VFP table I am using does not have null values. It uses some value
which Access sees as 12:00:00 AM (or Saturday, December 30, 1899 in long
date format) in query results. I am not sure how the Nz or Least function
will view this date?

"MGFoster" <me@privacy.com> wrote in message
news:YdyTb.8945$F23.3803@newsread2.news.pas.earthlink.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> For .mdb/e files - perhaps something like this:
>
> SELECT ID,
> Least(Date1, Date2, Date3, Date4, Date5, Date6) As SmallestDate
> FROM TableName
>
>
> The VBA function Least() that gets the Minimum date:
>
> Public Function Least(ParamArray var()As Variant) As Variant
>
> Dim min As Variant
> Dim i As Integer
>
> ' Initialize
> min = LBound(var)
> For i = LBound(var) to UBound(var)
> If var(i) < min Then min = var(i)
> Next i
>
> Least = min
>
> End Function
>
> This function can be more refined so it doesn't run when there is an
> empty array and you can add error handlers.
>
> You could also put Nz() around the Date fields in the SELECT clause to
> avoid getting NULLs in the Date fields. ***** This raises the
> question of what to do when there is a null date? You might want to
> put the default date at a very hi value - then it won't be selected
> when run thru the Least() function. Or, you may want to know when the
> date value is NULL - then allow Nz() to change the value to ZERO,
> which would be the lowest value.
>
> In either case use the Nz() function:
>
> Nz(NULL,0) = 0
> Nz(NULL, #1/1/9999#) = 1/1/9999
>
> - --
> MGFoster:::mgf00 <at> earthlink <decimal-point> net
> Oakland, CA (USA)
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGP for Personal Privacy 5.0
> Charset: noconv
>
> iQA/AwUBQB6wAIechKqOuFEgEQJ/HgCfVzv/mD+41xLXksyQEHIVCrx15PgAnjzI
> GUkv1XbRnKYnd1sCt6DzMZ/1
> =tR/l
> -----END PGP SIGNATURE-----
>
>
> Randal wrote:
>
> > I have 6 fields in a table that contain dates. I need to pull the
earliest
> > date from all 6 fields into one field in a query. Is there a function
in
> > access to do this? thanks,
> >
> >
>



Relevant Pages

  • Re: Help with Excel VBA QUOTIENT
    ... In Excel 2003 VBA, I click on Help> About Microsoft Visual Basic. ... you are misleading yourself by formatting G40 to have zero decimal places or because you happen to choose integers in E20 and E38 such that it does not matter. ... Dim Ratio as Long ...
    (microsoft.public.excel.programming)
  • Problem transferring array data onto worksheet using Resize
    ... When I type the example code from John Green's "Excel 2000 VBA ... Dim vaDiscount() As Variant ... When I try to use this technique my processed data is not being ...
    (microsoft.public.excel.programming)
  • Re: Dictionary object: Error assigning user defined data type to item
    ... But, if you have a problem with an array, a simple ... workaround is to create a variant, redim it to an array and use the ... Dim x As Dictionary ... Excel, PowerPoint, and VBA add-ins, tutorials ...
    (microsoft.public.excel.programming)
  • Re: Any way to use "standard" Excel functions inside VBA functions
    ... You can call worksheet functions from VBA code (except for those ... Dim D As Variant ... Error typed Variant. ...
    (microsoft.public.excel.programming)
  • Re: Help with Excel VBA QUOTIENT
    ... better for me if I omit the INT and just use the ratio as suggested by ... WorksheetFunction.Quotient is not valid in my revision of Excel 2003 / VBA ... So I get a VBA error, not zero. ... Dim Denominator As Range ...
    (microsoft.public.excel.programming)