Solved Compare Dates (1 Viewer)

mike60smart

Registered User.
Local time
Today, 02:44
Joined
Aug 6, 2017
Messages
1,913
Hi Everyone

I have a Subform which contains the following Unbound Controls

=[cboCarrier].Column(4) Control name is txtIns which displays the following Date: 11/04/1968
=[cboCarrier].Column(5) Control name is txtCargo which displays the following Date: 11/04/1971
=Date() Control name is txtDate to display todays date: 28/12/2022

I am trying to use the after Update of cboCarrier to display a warning if the Dates are Less Than Todays Date.

The after Update event is as follows and it current does nothing and gives no error. Can someone point out where I am going wrong?

Any help appreciated.

Code:
Private Sub cboCarrier_AfterUpdate()

10        On Error GoTo cboCarrier_AfterUpdate_Error
20    If Me.txtDate > Me.txtIns Then
30    MsgBox "Insurance has Expired", vbCritical
35    Me.cboCarrier.SetFocus
40    End If
50    If Me.txtDate > Me.txtCargo Then
60    MsgBox "Cargo Insurance Expired", vbCritical
65     Me.cboCarrier.SetFocus
70    End If

80        On Error GoTo 0
90        Exit Sub

cboCarrier_AfterUpdate_Error:

100       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cboCarrier_AfterUpdate, line " & Erl & "."

End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:44
Joined
Feb 19, 2002
Messages
43,302
When you place dates in unbound textboxes, Access does not know they are date data types so you have to tell it. One way is to format the control to a date format such as Short Date.

The other alternative, is to reference the .Column property directly.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:44
Joined
May 21, 2018
Messages
8,536
Another way is to wrap with a cdate. cdate(me.txtins) >...
Or
=Cdate([cbocarrier].column(5))
 
Last edited:

mike60smart

Registered User.
Local time
Today, 02:44
Joined
Aug 6, 2017
Messages
1,913
Another way is to wrap with a cdate. cdate(me.txtins) >...
Or
=Cdate([cbocarrier].column(5))
Hi Pat & MajP

Pat I had formatted the dates as ShortDate

MajP That works just great.

Many thanks both for looking
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:44
Joined
Feb 19, 2002
Messages
43,302
Pat I had formatted the dates as ShortDate
How? Did you set the format property of the control or did you use the Format() function?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:44
Joined
Feb 19, 2002
Messages
43,302
That has always worked for me. It could be that you are not using US standard date formatting and that is causing the confusion. At least the cdate() works for you,
 

Users who are viewing this thread

Top Bottom