Does the field in question on the table have to be in ascending order
for this to work?
Don't really understand what you mean: you said you wanted the value
before the one the user chose. Oh hold on -- you want the next one _down_
not up, sorry. Try this
With MyCombo
' bug out if it's the bottom row
If .ListIndex = .ListCount -1 Then exit sub
' get the next value down
TempDate = .ItemData(.ListIndex +1)
' and put it somewhere
MyInvisibleTextBox.Value = TempDate
End With
I suppose I could make a query out of the table first.
If this means what I think you mean, then YES you should use a rowsource
like
SELECT ALL MyDate
FROM MyDatesTable
WHERE Something=TRUE
ORDER BY MyDate DESC
You cannot trust an unsorted table recordset under any circumstances.
Note that the listbox itself must be UNsorted, because in USian
03/20/2005 comes after 04/20/2004 but it would be sorted alphabetically
in front of it.
I will use the text box names in the query criteria, something like
this:
Between Forms!Namefrm!txtLow And Forms!Namefrm!txtHigh
' you need whether using text boxes or variables: Jet is NOT
' regionally-friendly
Const fmtJetDate As String = "\#yyyy\-mm\-dd\#"
' force proper date manipulations: text strings can be
' badly screwed
Dim NextDate as Date
Dim PriorDate as Date
NextDate = CDate(cboMyCombo.Value)
PriorDate = CDate(GetPriorValueFrom(cboMyCombo)) ' see above!
' You can use BETWEEN, but it may get snagged if there are
' time values embedded in the records.
'
' The rigorous way is to use inequalities, so that all
' date time values are included up to (but not including)
' midnight on the following day, vis:-
'
jetCriterion = _
"SomeDate >= " & Format(PriorDate, fmtJetDate) & _
"AND SomeDate < " & Format(NextDate+1, fmtJetDate)
' Do this until you really know that it's getting the correct values
MsgBox jetCriterion
Just like eating an elephant -- one bite at a time. If you are going to
be coming back to this code in a couple of months, make sure you leave
lots of comment lines -- at least 50% and preferably about 2:1.
Hope it helps
Tim F