473,385 Members | 1,531 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.

CDate conversion question

1
Hi all,

I am a novice with access programming.And just started to learn.
I have a question similar to one of the posts in this forum.
I have a semester field that shoudl have input data in the format FSYYYY, SSYYYY OR SUYYYY (SS- spring, FS- Fall, SU-Summer and YYYY is the 4 digit year format.)
E.g. FS2010 for current semester.

The semesters in the university where i work run like this:

SS - 1/10/ TO 5/24/

SU - 6/6/ TO 8/9/

FS - 8/15/ TO 12/23/

i want to have a code that can check the current date with the above date ranges and and insert a yes if the semester is current and no if it is not.

That is if it is FS2010 then it is the current semester and Active field is "Yes"

I tried to use a code that is not mine(have found it in this forum), but i can't get it to work:



============================================

Expand|Select|Wrap|Line Numbers
  1. Private Sub Stu_title_subform_Current()
  2. '  03/SP
  3. 'CDate : If you have a string or an expression that you want to convert to a date value, use  CDate()  based on the following formula:Result = CDate(Value to Convert)
  4.  
  5.   Select Case Left(Semester, 2)
  6.   Case "SS"
  7.    If Date >= CDate(Left(Semester, 2) & "1/10/") And Date <= CDate(Left(Semester, 2) & "5/24/") Then
  8.     Me.Active = "Yes"
  9. Else
  10.     Me.Active = "No"
  11. End If
  12.    Case "SU"
  13. If Date >= CDate(Left(Semester, 2) & "6/6/") And Date <= CDate(Left(Semester, 2) & "8/9/") Then
  14.       Me.Active = "Yes"
  15. Else
  16.     Me.Active = "No"
  17. End If
  18.    Case "Fs"
  19. If Date >= CDate(Left(Semester, 2) & "8/15/") And Date <= CDate(Left(Semester, 2) & "12/23/") Then
  20.     Me.Active = "Yes"
  21. Else
  22.     Me.Active = "No"
  23. End If
  24.  
  25.   End Select
  26.  
  27. End Sub
===============================================
Expand|Select|Wrap|Line Numbers
  1. Private Sub Semester_AfterUpdate()
  2.  
  3.  
  4. Select Case Left(Semester, 2)
  5. Case "SS"
  6. If Date >= CDate(Left(Semester, 2) & "1/10/") And Date <= CDate(Left(Semester, 2) & "5/24/") Then
  7.  
  8.     Me.Active = "Yes"
  9. Else
  10.     Me.Active = "No"
  11. End If
  12. Case "SU"
  13. If Date >= CDate(Left(Semester, 2) & "6/6/") And Date <= CDate(Left(Semester, 2) & "8/9/") Then
  14.       Me.Active = "Yes"
  15. Else
  16.     Me.Active = "No"
  17. End If
  18. Case "FS"
  19. If Date >= CDate(Left(Semester, 2) & "8/15/") And Date <= CDate(Left(Semester, 2) & "12/23/") Then
  20.     Me.Active = "Yes"
  21. Else
  22.     Me.Active = "No"
  23. End If
  24.  
  25. End Select
  26.  
  27. End Sub
i don't know where it is going wrong

Any help is much appreciated.


Thanks
m_i
Aug 19 '10 #1
1 2036
colintis
255 100+
The problem I see in here is you are trying to convert a string to date. The output from CDate(Left(Semester, 2) & "1/10/") is "SS1/10/". So you should change to the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Stu_title_subform_Current()
  2. '  03/SP
  3. 'CDate : If you have a string or an expression that you want to convert to a date value, use  CDate()  based on the following formula:Result = CDate(Value to Convert)
  4.  
  5.   Select Case Left(Semester, 2)
  6.   Case "SS"
  7.    If Date >= CDate("1/10/" & Right(Semester, 4)) And Date <= CDate("5/24/" & Right(Semester, 4)) Then
  8.     Me.Active = "Yes"
  9. Else
  10.     Me.Active = "No"
  11. End If
  12.    Case "SU"
  13. If Date >= CDate("6/6/" & Right(Semester, 4)) And Date <= CDate("8/9/" & Right(Semester, 4)) Then
  14.       Me.Active = "Yes"
  15. Else
  16.     Me.Active = "No"
  17. End If
  18.    Case "Fs"
  19. If Date >= CDate("8/15/" & Right(Semester, 4)) And Date <= CDate("12/23/" & Right(Semester, 4)) Then
  20.     Me.Active = "Yes"
  21. Else
  22.     Me.Active = "No"
  23. End If
  24.  
  25.   End Select
  26.  
  27. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Semester_AfterUpdate()
  2.  
  3.     Select Case Left(Semester, 2)
  4.         Case "SS"
  5.             If Date >= CDate("1/10/" & Right(Semester, 4)) And Date <= CDate("5/24/" & Right(Semester, 4)) Then
  6.  
  7.                 Me.Active = "Yes"
  8.             Else
  9.                 Me.Active = "No"
  10.             End If
  11.         Case "SU"
  12.             If Date >= CDate("6/6/" & Right(Semester, 4)) And Date <= CDate("8/9/" & Right(Semester, 4)) Then
  13.                   Me.Active = "Yes"
  14.             Else
  15.                 Me.Active = "No"
  16.             End If
  17.         Case "FS"
  18.             If Date >= CDate("8/15/" & Right(Semester, 4)) And Date <= CDate("12/23/" & Right(Semester, 4)) Then
  19.                 Me.Active = "Yes"
  20.             Else
  21.                 Me.Active = "No"
  22.             End If
  23.     End Select
  24.  
  25. End Sub
Notice, Right(Semester, 4) will get the 4 characters from the right, which is the "2010". So ("1/10/" & Right(Semester, 4)) will become "1/10/2010", and remember to get the Date having the same date format (e.g. mm/dd/yyyy) to your CDate date, otherwise there it will be confusing to the codes with month and day.
Aug 20 '10 #2

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

Similar topics

1
by: Newsgroup - Ann | last post by:
Hi, I got a question a tricky type conversion: double * ==> const double * and double ** ==> const double * const * are both permitted, while double ** ==> const double ** is NOT permitted. ...
4
by: John Cho | last post by:
Class Cartesian { double x; double y; public: Cartesian( ) { x = 0.0 ; y = 0.0;} Cartesian(double x1, double y1) { x = x1; y = y1;} }; class Polar { double radius;
2
by: Tao Lu | last post by:
class A { pub: A(const char*); //1 A(char *); //2 } ; if i do A a("blah"); which constructor should be called?
1
by: Mark Reed | last post by:
Does anyone know if there are any problems that can occur when an office suite is upgraded from 97 to XP? All that databases have been created using 97 and we are soon to move over to XP and I have...
19
by: Randy Yates | last post by:
Consider the following code: #include "dsptypes.h" /* definitions */ #define VECTOR_LENGTH 64 /* local variables */
2
by: Paul Hetherington | last post by:
Hi, Which is the more recomended way to do type conversion in C# for basic data types(integer, singles, doubles etc...) System.Convert.ToSingle,ToInt32 etc...? or (float)myvar; (int)myvar, ...
6
by: KA Kueh | last post by:
Dear all, I have a requirement to replace the ' character with ASCII character (146) in C# but it seems that when I do the following the conversion is lost. char t = Convert.ToChar(146);...
2
by: fabricemarchant | last post by:
Hi ! If we define such conversion operator for Zclass : class ZClass { operator char*(void); }; How can we write explicit conversion without using this :
11
by: 1230987za | last post by:
Hi, I am totally confused now about C type conversion. I know that C does some implicit type conversion like integer promotion and float to double. I imagine that such conversion must keep the...
13
by: =?Utf-8?B?RGF2ZSBXZWVkZW4=?= | last post by:
Hi all, I'm having trouble with a project that I've distilled down to the following code. Unfortunately it won't compile and gives the following error (caused by the call to GetHorses() in...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.