Solved

DateDiff -- Type mismatch

Posted on 2002-05-13
6
707 Views
Last Modified: 2008-03-17
Have 2-txtboxes, where user enters date. I'd like to know the number of days between the entered dates:

If DateDiff("d", Me!txt0, Me!txt1) > 5 Then
Msgbox "5+"
End If

but I'm getting "Type MisMatch"

any ideas....
0
Comment
Question by:debbie790
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7006032
This can only be if the value in the textboxes is not a valid date

Try to check using the IsDate(Me!txt0.Text) if the value is recognized as a date or not.

CHeers
0
 
LVL 12

Accepted Solution

by:
Paurths earned 50 total points
ID: 7006033
try

If DateDiff("d", CDate(Me!txt0), CDate(Me!txt1)) > 5 Then
Msgbox "5+"
End If

cheers
Ricky

0
 
LVL 44

Expert Comment

by:bruintje
ID: 7006048
Hi Debbie790,

-you should be sure there are dates entered in the textboxes
-make their format property something like short date
-and then you can do something like

If DateDiff("d", CDate(Me!Txt0), CDate(Me!Txt1)) > 5 Then

-and better rename your date boxes to something meaningful for easier reading

HTH:O)Bruintje
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 44

Expert Comment

by:bruintje
ID: 7006051
next i'll refresh first :)
0
 
LVL 1

Expert Comment

by:emorrie
ID: 7006098
DateDiff works on Date/Time field values.  It does not convert Text fields to Date/Time on the fly.  You can try the CDate function to convert a text string to a date before using datediff.

If DateDiff("d", CDate(Me!txt0), CDate(Me!txt1))>5 Then
    Do stuff here
End If
0
 
LVL 1

Expert Comment

by:emorrie
ID: 7006117
same here bruintje.

Sorry for the duplicate info
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question