Hello all,
I have a problem that in my code. My code creates the string I need fine, so I am going to abbreviate the code to illustrate my issue.
In my code I have run a query that gives me 1 to many rows in a recordset. I then determine between two fields which field for that row represents my PlanDate value. Then I place that value into a building string. Essentially if I had three rows in my recordset, my string would look like this:
#1/1/2009#,#1/2/2009#,#1/3/2009#
I am then trying to pass that string into the MaxofList Function written by Allen Browne. I know this funcion is working based on the following from my immediate window:
?MaxofList(#1/1/2009#,#1/2/2009#,#1/3/2009#)
1/3/2009
However, when I try to do this in VBA code it successfully moves to the MaxofList function in my Module, but for some reason it does not separate the values so the LBound and UBound both are showing as Zero when I step through the code. So it goes into the MaxofList loop and does not recognize a number or a date and returns nothing. Then when I get back to my code I am getting a Invalid use of Null Error because I am trying to place the MaxofList result value into a string or technically a forms textbox.
Below is the abbreviated code:
Also as I am stepping through the MaxofList code it shows the varValues(i) as the string:
"#1/1/2009#, #1/3/2009#, #1/4/2009#"
so it seems to me the variant is not separating on the commas and treating it as one array item. Then it is failing the IsNumeric and IsDate test and so varMax is Nothing.
Sorry here is the code for the Max of List function by Allen Browne:
So, can someone tell me what I am doing wrong when trying to pass the string into the MaxofList? Unfortunately, the only example of a Date passing to this function I have seen is through a query column. I can not pass from a query in this case.
Thanks in Advance,
Troy :-D
I have a problem that in my code. My code creates the string I need fine, so I am going to abbreviate the code to illustrate my issue.
In my code I have run a query that gives me 1 to many rows in a recordset. I then determine between two fields which field for that row represents my PlanDate value. Then I place that value into a building string. Essentially if I had three rows in my recordset, my string would look like this:
#1/1/2009#,#1/2/2009#,#1/3/2009#
I am then trying to pass that string into the MaxofList Function written by Allen Browne. I know this funcion is working based on the following from my immediate window:
?MaxofList(#1/1/2009#,#1/2/2009#,#1/3/2009#)
1/3/2009
However, when I try to do this in VBA code it successfully moves to the MaxofList function in my Module, but for some reason it does not separate the values so the LBound and UBound both are showing as Zero when I step through the code. So it goes into the MaxofList loop and does not recognize a number or a date and returns nothing. Then when I get back to my code I am getting a Invalid use of Null Error because I am trying to place the MaxofList result value into a string or technically a forms textbox.
Below is the abbreviated code:
Code:
strPlanDateValues = "#1/1/2009#, #1/3/2009#, #1/4/2009#"
If Len(strPlanDateValues) = 0 Then 'Populate Plan Field
KMGPlanStratMeet = Null
Else
strResult = MaxOfList(strPlanDateValues)
Me.KMGPlanStratMeet = strResult
End If
Also as I am stepping through the MaxofList code it shows the varValues(i) as the string:
"#1/1/2009#, #1/3/2009#, #1/4/2009#"
so it seems to me the variant is not separating on the commas and treating it as one array item. Then it is failing the IsNumeric and IsDate test and so varMax is Nothing.
Sorry here is the code for the Max of List function by Allen Browne:
Code:
Public Function MaxOfList(ParamArray varValues()) As Variant
Dim i As Integer 'Loop controller.
Dim varMax As Variant 'Largest value found so far.
varMax = Null 'Initialize to null
For i = LBound(varValues) To UBound(varValues)
If IsNumeric(varValues(i)) Or IsDate(varValues(i)) Then
If varMax >= varValues(i) Then
'do nothing
Else
varMax = varValues(i)
End If
End If
Next
MaxOfList = varMax
End Function
So, can someone tell me what I am doing wrong when trying to pass the string into the MaxofList? Unfortunately, the only example of a Date passing to this function I have seen is through a query column. I can not pass from a query in this case.
Thanks in Advance,
Troy :-D