Solved

DateDiff -- Type mismatch

Posted on 2002-05-13
6
698 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Comment Utility
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 Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 44

Expert Comment

by:bruintje
Comment Utility
next i'll refresh first :)
0
 
LVL 1

Expert Comment

by:emorrie
Comment Utility
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
Comment Utility
same here bruintje.

Sorry for the duplicate info
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now