Need help Please!!!

sean_churchill

New Member
Joined
Feb 20, 2003
Messages
11
Hi,

How do i compare two dates in a 'Form' and if they are more than six months apart how do i produce a error message?

One date is in a text box (Which is from a list in Table by the following name :- Latest DEM ISSUE NO) and the other is todays date which is done by this :- =format(Date(),"Short Date")

There are over 1000 different dates in the Table. i need it to check each one.

Please help!!!!

Many Thanks

Sean.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You seem to have two issue here. One is to check based on a form (for new data?), the other is to run some code to check existing data.

Here is some code that will work for your form need. To test it, create a new form with a textbox and a command button only. Paste this code in for the command button click event. It will give you a msgbox based on the difference in today's date and the date typed into the textbox.

Private Sub Command2_Click()
Dim lngDiff As Long
Dim strMsg As String

lngDiff = DateDiff("m", Now, Me.Text0)
strMsg = "DateDiff = " & lngDiff

If lngDiff = 6 Then
If Day(Me.Text0) > Day(Now) Then
strMsg = strMsg & " - Error"
End If
ElseIf lngDiff > 6 Then
strMsg = strMsg & " - Error"
End If

MsgBox strMsg

End Sub

If you need to run this on a lot of data, use this as the basis for a subroutine to execute on all the dates in the table.

HTH
 
Upvote 0

Forum statistics

Threads
1,221,497
Messages
6,160,152
Members
451,625
Latest member
sukhman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top