If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
using the greater of 4 dates
I have 4 date fields (one of the dates could be empty) on my form - I want to
prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#2
|
|||
|
|||
Function HighDate(dtmDate1 As Date, dtmDate2 As Date, dtmDate3 As Date, _
dtmDate4 As Date) As Date Dim varDates As Variant Dim intX As Integer Dim dtmHighDate As Date varDates = Array(dtmDate1, dtmDate2, dtmDate3, dtmDate4) For intX = 0 To 3 If varDates(intX) dtmHighDate Then dtmHighDate = varDates(intX) End If Next intX HighDate = dtmHighDate End Function "dchristo" wrote: I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#3
|
|||
|
|||
Dim DATE1 As Date, DATE2 As Date, DATE3 As Date, HIGHDATE As Date
DATE1 = Forms!Form1.[Date1] DATE2 = Forms!Form1.[Date2] DATE3 = Forms!Form1.[Date3] If DATE1 HIGHDATE Then HIGHDATE = DATE1 If DATE2 HIGHDATE Then HIGHDATE = DATE2 If DATE3 HIGHDATE Then HIGHDATE = DATE3 Forms!Form1.[highdate]=HIGHDATE thats all -- Message posted via http://www.accessmonster.com |
#4
|
|||
|
|||
Here is a generic function that will accept any number of values and return
the maximum of them: Public Function MaxValueVariantArray(ParamArray ValuesArray() As Variant) As Variant ' ** THIS FUNCTION RETURNS THE MAXIMUM VALUE FROM AN ARRAY OF VALUES. ' Ken Snell 19 May 2005 Dim xlngLB As Long, xlngUB As Long, xlngCnt As Long Dim xvarTp As Variant xlngLB = LBound(ValuesArray) xlngUB = UBound(ValuesArray) If xlngUB = 0 And xlngLB = 0 Then xvarTp = ValuesArray(xlngLB) For xlngCnt = xlngLB + 1 To xlngUB If ValuesArray(xlngCnt) xvarTp Then xvarTp = ValuesArray(xlngCnt) Next xlngCnt End If MaxValueVariantArray = xvarTp End Function -- Ken Snell MS ACCESS MVP "dchristo" wrote in message ... I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#5
|
|||
|
|||
Ok, I am having difficulty making this work, I have a text box that I want to
prepopulate with formula that you have given me. But when it put in before update I does not work, Can you please help me out? also, every date but the Date Foreclosure Sale is showing up 12:00 AM Private Sub Text335_BeforeUpdate(Cancel As Integer) Dim First_Time_Vacancy As Date, Redemption_Date As Date, Marketable_Title_Date As Date, Date_Foreclosure_Date As Date, HIGHDATE As Date First_Time_Vacancy = Forms!Borrower_Information.[First Time Vacancy] Redemption_Date = Forms!Borrower_Information.[Redemption Date] Marketable_Title_Date = Forms!Borrower_Information.[Marketable Title Date] Date_Foreclosure_Sale = Forms!Borrower_Information.[Date Foreclosure Sale] If First_Time_Vacancy HIGHDATE Then HIGHDATE = First_Time_Vacancy If Redemption_Date HIGHDATE Then HIGHDATE = Redemption_Date If Marketable_Title_Date HIGHDATE Then HIGHDATE = Marketable_Title_Date If Date_Foreclosure_Sale HIGHDATE Then HIGHDATE = Date_Foreclosure_Sale Forms!Borrower_Information.[HIGHDATE] = HIGHDATE End Sub "dchristo" wrote: I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#6
|
|||
|
|||
Did you try the function that I posted?
-- Ken Snell MS ACCESS MVP "dchristo" wrote in message ... Ok, I am having difficulty making this work, I have a text box that I want to prepopulate with formula that you have given me. But when it put in before update I does not work, Can you please help me out? also, every date but the Date Foreclosure Sale is showing up 12:00 AM Private Sub Text335_BeforeUpdate(Cancel As Integer) Dim First_Time_Vacancy As Date, Redemption_Date As Date, Marketable_Title_Date As Date, Date_Foreclosure_Date As Date, HIGHDATE As Date First_Time_Vacancy = Forms!Borrower_Information.[First Time Vacancy] Redemption_Date = Forms!Borrower_Information.[Redemption Date] Marketable_Title_Date = Forms!Borrower_Information.[Marketable Title Date] Date_Foreclosure_Sale = Forms!Borrower_Information.[Date Foreclosure Sale] If First_Time_Vacancy HIGHDATE Then HIGHDATE = First_Time_Vacancy If Redemption_Date HIGHDATE Then HIGHDATE = Redemption_Date If Marketable_Title_Date HIGHDATE Then HIGHDATE = Marketable_Title_Date If Date_Foreclosure_Sale HIGHDATE Then HIGHDATE = Date_Foreclosure_Sale Forms!Borrower_Information.[HIGHDATE] = HIGHDATE End Sub "dchristo" wrote: I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#7
|
|||
|
|||
Well to be honest, I am totally confused now. This is what I have, but I am
clueless here, can you help me out? Private Sub Text342_BeforeUpdate(Cancel As Integer) Public Function MaxValueVariantArray(First_Known_Vacancy, Redemption_Period, Marketable_Title_Date, Date_Foreclosure_Sale) As Variant Dim xlngLB As Long, xlngCnt As Long Dim xvarTp As Variant xlngLB = LBound(First_Known_Vacancy,Redemption_Period,Marke table_Title_Date,Date_Foreclosure_Sale) xlngUB = UBound(First_Known_Vacancy,Redemption_Period,Marke table_Title_Date,Date_Foreclosure_Sale) If xlngUB = 0 And xlngLB = 0 Then xvarTp = ValuesArray(xlngLB) For xlngCnt = xlngLB + 1 To xlngUB If ValuesArray(xlngCnt) xvarTp Then xvarTp -ValuesArray(xlngCnt) Next xlngCnt End If MaxValueVariantArray = xvarTp End Function "Ken Snell [MVP]" wrote: Did you try the function that I posted? -- Ken Snell MS ACCESS MVP "dchristo" wrote in message ... Ok, I am having difficulty making this work, I have a text box that I want to prepopulate with formula that you have given me. But when it put in before update I does not work, Can you please help me out? also, every date but the Date Foreclosure Sale is showing up 12:00 AM Private Sub Text335_BeforeUpdate(Cancel As Integer) Dim First_Time_Vacancy As Date, Redemption_Date As Date, Marketable_Title_Date As Date, Date_Foreclosure_Date As Date, HIGHDATE As Date First_Time_Vacancy = Forms!Borrower_Information.[First Time Vacancy] Redemption_Date = Forms!Borrower_Information.[Redemption Date] Marketable_Title_Date = Forms!Borrower_Information.[Marketable Title Date] Date_Foreclosure_Sale = Forms!Borrower_Information.[Date Foreclosure Sale] If First_Time_Vacancy HIGHDATE Then HIGHDATE = First_Time_Vacancy If Redemption_Date HIGHDATE Then HIGHDATE = Redemption_Date If Marketable_Title_Date HIGHDATE Then HIGHDATE = Marketable_Title_Date If Date_Foreclosure_Sale HIGHDATE Then HIGHDATE = Date_Foreclosure_Sale Forms!Borrower_Information.[HIGHDATE] = HIGHDATE End Sub "dchristo" wrote: I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#8
|
|||
|
|||
Just wanted to say Thank You, this works great
"Ken Snell [MVP]" wrote: Here is a generic function that will accept any number of values and return the maximum of them: Public Function MaxValueVariantArray(ParamArray ValuesArray() As Variant) As Variant ' ** THIS FUNCTION RETURNS THE MAXIMUM VALUE FROM AN ARRAY OF VALUES. ' Ken Snell 19 May 2005 Dim xlngLB As Long, xlngUB As Long, xlngCnt As Long Dim xvarTp As Variant xlngLB = LBound(ValuesArray) xlngUB = UBound(ValuesArray) If xlngUB = 0 And xlngLB = 0 Then xvarTp = ValuesArray(xlngLB) For xlngCnt = xlngLB + 1 To xlngUB If ValuesArray(xlngCnt) xvarTp Then xvarTp = ValuesArray(xlngCnt) Next xlngCnt End If MaxValueVariantArray = xvarTp End Function -- Ken Snell MS ACCESS MVP "dchristo" wrote in message ... I have 4 date fields (one of the dates could be empty) on my form - I want to prepopulate another field with the greater of the 4 dates. Can someone tell me how to accomplish this |
#9
|
|||
|
|||
You're welcome...
-- Ken Snell MS ACCESS MVP "dchristo" wrote in message ... Just wanted to say Thank You, this works great "Ken Snell [MVP]" wrote: Here is a generic function that will accept any number of values and return the maximum of them: |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
I can't remove the dates from Visio | Tom Rippert | Visio | 0 | March 25th, 2005 06:02 PM |
Crosstab query with irregularly-spaced dates | Carl Rapson | Running & Setting Up Queries | 2 | March 17th, 2005 10:42 PM |
Chart possible of dates vs. pounds? | GBL | General Discussion | 3 | July 6th, 2004 03:56 AM |
Vlookup with Dates - undocumented error! | Bob Phillips | Worksheet Functions | 3 | February 25th, 2004 01:39 PM |
If then, within range, greater than, etc. help | Dave Piper | Worksheet Functions | 12 | December 12th, 2003 01:22 PM |