I need to calculate a value for a date field. However, the month is evaluated to determine the start and end date. Therefore, the fields are declared as strings. The values are moved in for the month, day and year. Thereafter, the string needs to be converted into a date field to query on the date.
Any assistance, would be greatly appreciated.
The following is my current code: -
Private Sub txt_MM_cmb_AfterUpdate()
-
-
On Error GoTo Err_Hndlr
-
-
Dim txt_MM As String
-
Dim txt_dd_start As String
-
Dim txt_dd_end As String
-
Dim txt_yy As String
-
Dim txt_start As String
-
Dim txt_end As String
-
-
-
txt_MM = " "
-
txt_dd_start = " "
-
txt_dd_end = " "
-
txt_yy = "20" & [Forms]![F_Waiver_Yr]![Txt_Waiver_Yr]
-
txt_start = " "
-
txt_end = " "
-
-
-
-
txt_dd_start = "01"
-
-
Select Case Forms!F_Waiver_Yr!txt_MM_cmb
-
Case Is = "January"
-
txt_MM = "01"
-
txt_dd_end = "31"
-
Case Is = "February"
-
txt_MM = "02"
-
Dim Date1 As Date, Date2 As Date, IsLeapYear As Boolean
-
Date1 = "January 1," & Year(Now()): Date2 = "December 31," & Year(Now())
-
If DateDiff("d", Date1, Date2) = 365 Then
-
IsLeapYear = True
-
txt_dd_end = "29"
-
MsgBox " This is a Leap Year"
-
Else
-
txt_dd_end = "28"
-
End If
-
Case Is = "March"
-
txt_MM = "03"
-
txt_dd_end = "31"
-
Case Is = "April"
-
txt_MM = "04"
-
txt_dd_end = "30"
-
Case Is = "May"
-
txt_MM = "05"
-
txt_dd_end = "31"
-
Case Is = "June"
-
txt_MM = "06"
-
txt_dd_end = "30"
-
Case Is = "July"
-
txt_MM = "07"
-
txt_dd_end = "31"
-
Case Is = "August"
-
txt_MM = "08"
-
txt_dd_end = "31"
-
Case Is = "September"
-
txt_MM = "09"
-
txt_dd_end = "30"
-
Case Is = "October"
-
txt_MM = "10"
-
txt_dd_end = "31"
-
Case Is = "November"
-
txt_MM = "11"
-
txt_dd_end = "30"
-
Case Else
-
txt_MM = "12"
-
txt_dd_end = "31"
-
End Select
-
-
txt_start = txt_MM & txt_dd_start & txt_yy
-
txt_end = txt_MM & txt_dd_end & txt_yy
-
-
txt_start = Format(CDate([txt_start]), "mm/dd/yyyy")
-
txt_end = Format(CDate([txt_start]), "mm/dd/yyyy")
-
-
-
txt_MM_cmb_AfterUpdate_Exit:
-
-
Exit Sub
-
-
-
Err_Hndlr:
-
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "txt_MM_cmb_AfterUpdate()"
-
End Sub
-
5 1524
A quick example of using CDate(). - Private Sub TEST_CDate()
-
Dim myString As String
-
Dim myDate As Date
-
myString = "February 12, 1969 11:59:59 PM"
-
myDate = CDate(myString)
-
End Sub
Oralloy,
The string data would need to be converted from the form of "02/28/2010" to a date field "02/28/2010." from what i understand of CDate it converts the spelled out date, therefore, my date would be 02/12/1969. i looked into this hopefully and was disappointed since it doesn't actually convert a numeric string.
Thanks anyway.
mary
Mary,
I just tried it with your date in Access 2007, and it looks like the date converted correctly in the locals window.
Give it a try and see?
Luck!
Oralloy,
My apologies for the delayed response. However, the simplest approach was to move the string value into the date field.
Thank you for your help.
Mary
Mary,
No problems. Hopefully it helped a little.
I often prefer explicit conversions to implicit conversions, as it lets me know what's going on in the code when I have to revisit it later. I'm a little gun-shy about conversions because I've had to debug and clean up lots of code where implicit conversions worked in the "success" cases, and caused terrible things to happen when bogus values are entered by the user.
Anyway - I sure hope your project is working out well.
Cheers!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Noyb |
last post by:
How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field....
|
by: Droope |
last post by:
I have a date field in a SQL table that allows null.
If certain conditions are met in the user interface I need to set the field to nulls.
using a typed dataset I do the following
Dim...
|
by: peashoe |
last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an
exact date format in the text field (txtDDate). My problem is I need
some javascript that sets an alert that does not allow them...
|
by: usenet |
last post by:
I have inherited a table where date information was saved from PHP as a VARCHAR.
(Sigh.) This means that the so-called date fields look like this :
August 1, 2005, 9:09 am EDT
October 13, 2004,...
|
by: Fran Zablocki |
last post by:
I have a process that exports an Access table to a comma-delimited
text file. One of the fields that is exported shows the date it was
exported, using the Date() function. In the Access table, the...
|
by: Kevin Hodgson |
last post by:
I'm trying to import from a text file into a Sql DB, but I'm getting hung up
on a date field.
My text file has the date in the dd/mm/yyyy format.
I Cast that field to CDate in VB.NET, which sets...
|
by: itfgnanvigneshwari |
last post by:
hai,
as i am new to php field i had a problem in date field. i have table named student with fields
fieldname type
name varchar...
|
by: satishrajana |
last post by:
Hi,
My SQL returns a NULL in a datefield if there is no date in that field.
If there is a NULL in this column, I want to replace it with spaces in
my SELECT statement when I am selecting these...
|
by: Thorben Grosser |
last post by:
Hey again newsgroup,
I am still working on an archive database and got another problem: I
have to classify the folders by a date or a date range which has the
format mm/yyyy
I got the feeling,...
|
by: veer |
last post by:
Hi
I have a probleum in vconverting a string value into date in vb.net
e.g
str="31.12.2005"
i want to convert it into date format like "mm/dd/yyyy"
i use CDATE function for it but every time...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |