Solved

DateDiff -- Type mismatch

Posted on 2002-05-13
6
701 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]
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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