Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatening Date & Time Field for Comparison 2

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
Hi,

The following code is attempting to compare which of the date and time fields is greater.

The Me.txtFlatFileUpdate control gets its value from a function which gets the date/time of a file on the network.

The Me.txtLastUpdateDateTime control gets its value from a field in a table which is a concatenation of two separate date and time fields in the same table.

The comparison does not work. It always says the Me.txtFlatFileUpdate is greater than the Me.txtLastUpdateDateTime

Private Sub Form_Open(Cancel As Integer)

If Me.txtFlatFileUpdate > Me.txtLastUpdateDateTime Then
Call MsgBox("The FlatFile Update is greater than the Last Update")
Else
Call MsgBox("The Last Update is greater than the FlatFile Update")
End If

End Sub

Any ideas?

Thanks!
 
How are ya dmon000 . . .

Try this:
Code:
[blue]   If CDate(Me.txtFlatFileUpdate) > CDate(Me.txtLastUpdateDateTime) Then[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks AceMan for the code. The first couple of times I tried it, it was great. But now it returns a "Run Time Error 13: Type Mismatch"

I honestly did not change any settings, fields, etc. What the heck could be wrong?

Here's my implementation:

Private Sub Form_Open(Cancel As Integer)

If CDate(Me.txtFlatFileUpdate) > CDate(Me.txtLastUpdateDateTime) Then
Call MsgBox("The FlatFile Update is greater than the Last Update")
Else
Call MsgBox("The Last Update is greater than the FlatFile Update")
End If

End Sub

Thanks Again
 
I'd use the Load event procedure instead of the Open.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Tried the On Load event. No difference.

How can this thing be so flakey?
 
dmon000 . . .

Only thing I can think of is your loading a large recordset. If this is true try this in the [blue]OnLoad[/blue] event :
Code:
[blue]   Dim rst As DAO.Recordset
   
   Set rst = Me.RecordsetClone
   rst.MoveLast
   DoEvents
   Set rst = Nothing
      
   If CDate(Me.txtFlatFileUpdate) > CDate(Me.txtLastUpdateDateTime) Then
      Call MsgBox("The FlatFile Update is greater than the Last Update")
   Else
      Call MsgBox("The Last Update is greater than the FlatFile Update")
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
It might help you to determine the problem if you print out the values you're comparing to the debug window:
Code:
   [COLOR=blue]
   debug.print "FlatFile date: " & CDate(Me.txtFlatFileUpdate)
   debug.print "LastUpdate date: " & CDate(Me.txtLastUpdateDateTime)
   [/color]
   If CDate(Me.txtFlatFileUpdate) > CDate(Me.txtLastUpdateDateTime) Then
      Call MsgBox("The FlatFile Update is greater than the Last Update")
   Else
      Call MsgBox("The Last Update is greater than the FlatFile Update")
   End If

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top