need code to decide which date was inputed first

sp00k

Registered User.
Local time
Today, 12:29
Joined
Jan 12, 2009
Messages
40
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
 
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
 
earliestdate:IIF([text1]<[text2],[text1],[text2])

assuming date fields else conversion required.

Brian
 
first date as in first entered, sorry for the confusion.
 
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
 
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.
 
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
 
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.
 
excellent idea, still not quite sure how I would write an expression to take the date from the first box, and not the second.
 
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.
 

Users who are viewing this thread

Back
Top Bottom