473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem using CDate with date as string datatype

97
Hi,

I am facing some problems using date expression as string datatype.
Here's clip of my code.
The (Intvdate) is string datatype in the MySQL linked table.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.   Dim strToday As String
  4.   Dim noBeforeDay As String
  5.   Dim Intvdate As String
  6.  
  7.   strToday = Date
  8.   noBeforeDay = "04/01/2007"
  9.  
  10.        If CDate((Me.Intvdate) > strToday) Then
  11.                MsgBox "Today is " & strToday & "!" & vbNewLine & _
  12.                 "Completion date cannot be later than today. Please fix!"
  13.                Intvdate.SetFocus
  14.                Cancel = True
  15.                Me.Intvdate = ""
  16.         End If
  17.  
  18.         If CDate((Me.Intvdate) < noBeforeDay) Then      
  19.                MsgBox "Completion date cannot be earlier than 04/01/2007. Please fix"
  20.                Intvdate.SetFocus
  21.                Cancel = True
  22.                Me.Intvdate = ""
  23.         End If
  24.  
  25. End Sub
The problem is that the message is triggered ("...cannot be earlier than 04/01/2007") even if the intvdate entered is "01/10/2008"

Can anyone tell me how to correctly convert the string into date while the datatype is string? Thank you for your help!
Jan 10 '08 #1
4 5971
puppydogbuddy
1,923 Expert 1GB
Hi,

I am facing some problems using date expression as string datatype.
Here's clip of my code.
The (Intvdate) is string datatype in the MySQL linked table.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.   Dim strToday As String
  4.   Dim noBeforeDay As String
  5.   Dim Intvdate As String
  6.  
  7.   strToday = Date
  8.   noBeforeDay = "04/01/2007"
  9.  
  10.        If CDate((Me.Intvdate) > strToday) Then
  11.                MsgBox "Today is " & strToday & "!" & vbNewLine & _
  12.                 "Completion date cannot be later than today. Please fix!"
  13.                Intvdate.SetFocus
  14.                Cancel = True
  15.                Me.Intvdate = ""
  16.         End If
  17.  
  18.         If CDate((Me.Intvdate) < noBeforeDay) Then      
  19.                MsgBox "Completion date cannot be earlier than 04/01/2007. Please fix"
  20.                Intvdate.SetFocus
  21.                Cancel = True
  22.                Me.Intvdate = ""
  23.         End If
  24.  
  25. End Sub
The problem is that the message is triggered ("...cannot be earlier than 04/01/2007") even if the intvdate entered is "01/10/2008"

Can anyone tell me how to correctly convert the string into date while the datatype is string? Thank you for your help!
You are on the right track with CDate, except you did not apply it to all of your date strings.

strToday = Date()
noBeforeDay = "04/01/2007"

If CDate(Me.Intvdate) > CDate(strToday) Then
If CDate(Me.Intvdate) < CDate(noBeforeDay) Then
Jan 11 '08 #2
loisk
97
You are on the right track with CDate, except you did not apply it to all of your date strings.

strToday = Date()
noBeforeDay = "04/01/2007"

If CDate(Me.Intvdate) > CDate(strToday) Then
If CDate(Me.Intvdate) < CDate(noBeforeDay) Then
Hi Puppydogpuppy,

Thanks for your reply!
I thought I applied all of my strings by wrapping both expressions, i.e., CDate((Me.Intvdate) > noBeforeDay).
Jan 11 '08 #3
puppydogbuddy
1,923 Expert 1GB
Hi Puppydogpuppy,

Thanks for your reply!
I thought I applied all of my strings by wrapping both expressions, i.e., CDate((Me.Intvdate) > noBeforeDay).
No, CDate must be applied individulally to each date string. Consequently, strToday and noBefore'Day remain as date strings that must be converted to Date values for evaluation.in your expressions: For example, the correct expression for CDate((Me.Intvdate) > noBeforeDay) is CDate(Me.Intvdate) > CDate(noBeforeDay).
Jan 11 '08 #4
loisk
97
No, CDate must be applied individulally to each date string. Consequently, strToday and noBefore'Day remain as date strings that must be converted to Date values for evaluation.in your expressions: For example, the correct expression for CDate((Me.Intvdate) > noBeforeDay) is CDate(Me.Intvdate) > CDate(noBeforeDay).
I see! Thank you so much for your help!
Jan 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
10
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
3
by: Coen | last post by:
I have a datagrid bound to a dataset's table. I'm using a tablestyle and so I can, with the column.format property, format numeric and date typed datacolumns. But I need to format a column of type...
1
by: sck10 | last post by:
Hello, I am pulling data from a SQL Server table. One field that is (varchar 4000) is used to show notes. I am using a FormView for showing and editing the data. When the form is in Item...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
2
by: perfectvijay | last post by:
hi actually i tried to use the string datatype in c++ on turbo 3.0 c++ complier i had included even the #include<string.h> and actually the header file is also present but during complation it is...
2
by: ncsthbell | last post by:
I have a string datatype column which contains values such as '1841000'. The value should be '18410'. I have tried the following: Replace(RTrim(Replace(MyValue, "0", " ")), " ", "0") The problem...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.