View Full Version : need code to decide which date was inputed first


sp00k
01-23-2009, 05:02 AM
Pretty new to vba, I need to make a control grab the first date entered from two text boxes. I have tried doing this in expression builder, but it was getting pretty complicated(not sure if you can do variables in expression builder)

If anyone can help me out that would be great

Vonnie
01-23-2009, 06:50 AM
first date as in earliest date? not first data entered?
You can compare the values of the textboxes
If CDate(Text1) > CDate(Text3) Then
strdate = Text1 'Text1 is newer
Else
strdate = Text3 'text3 is newer
End If

Brianwarnock
01-23-2009, 07:06 AM
earliestdate:IIF([text1]<[text2],[text1],[text2])

assuming date fields else conversion required.

Brian

sp00k
01-23-2009, 07:32 AM
first date as in first entered, sorry for the confusion.

Brianwarnock
01-23-2009, 07:36 AM
I don't see how you can know that, if they were in the same column in a table then First might just give you it , but dodgy, to know the earliest of anything the recommended way is to date it, then Min date or a comparison for smallest is the only way.

Brian

chergh
01-23-2009, 07:46 AM
you could have a couple of hidden text boxes that are updated with the now function using the change event of your two text boxes.

sp00k
01-23-2009, 07:54 AM
Its for a project name, they don't want the project name to change if someone has an earlier time, they just want it dated with the first date inputted(not my idea). I will try the hidden text box idea, not really sure how to implement it, but i'll play around and see what I can do

Vonnie
01-23-2009, 08:53 AM
They do force us to be creative. If you have access to the data design, you could have another NOW datafield to compare - If there was already a value in it , then don't update the project name.

sp00k
01-23-2009, 09:13 AM
excellent idea, still not quite sure how I would write an expression to take the date from the first box, and not the second.

Vonnie
01-23-2009, 10:09 AM
There are probably alot of ways to do this. Depends on how much you want to give the user edit rights also. If you want to avoid alot of coding, you would have 2 NOW fields for both textbox fields (basically flags for when they were first set)
If there was a value in their NOW field, you wouldn't allow that field to be updated again. Then you can always compare the 2 NOW fields to see which was set earlier (first) - so it wouldn't matter what the dates are in the textboxes, the NOW fields tell you when they were set. You could do it with one NOW field too, just more complex coding.