My form has two text boxes, txtDateFrom and txtDateTo. A macro button with the caption Month is to automatically fill in txtDateFrom and txtDateTo with current month date. My code reads as: - Private Sub cmdmonth_Click()
-
'Sets the Date From and Date To text boxes
-
'to show complete month (from start to end of current month)
-
-
Me!txtdatefrom = CDate("01/" & Month(Date) & "/" & Year(Date))
-
Me!txtDateTo = DateAdd("d", -1, DateAdd("m", 1, Me!txtdatefrom))
-
-
End Sub
But it's giving me wrong date: 1/5/09 and 2/4/09. I expect it to show 5/1/09 and 5/31/09
By the way, macros for Today, Week and Year are working just fine. These codes are as follow: TODAY - Private Sub cmdtoday_Click()
-
'Sets the Date From and Date To text boxes
-
'to Today's Date
-
-
Me!txtdatefrom = Date
-
Me!txtDateTo = Date
-
-
End Sub
THIS WEEK - Private Sub cmdweek_Click()
-
'Sets the Date From and Date To text boxes
-
'to show complete working week (Mon - Fri)
-
-
Dim today
-
-
today = Weekday(Date)
-
-
Me!txtdatefrom = DateAdd("d", (today * -1) + 2, Date)
-
Me!txtDateTo = DateAdd("d", 6 - today, Date)
-
-
End Sub
I need your experties to help me with my code for MONTH. Thanks.
11 2076
To get current month (05/01/2009 - 05/31/2009) I modified the code to read as: - Private Sub cmdmonth_Click()
-
'Sets the Date From and Date To text boxes
-
'to show complete month (from start to end of current month)
-
-
Me!txtdatefrom = DateAdd("m", (today * -1), Date)
-
Me!txtDateTo = DateAdd("d", -1, DateAdd("m", 1, Me!txtdatefrom))
-
-
End Sub
but the end result has been 5/15/2009 - 6/14/2009.
Is it possible to get This month instead of a month from today?
Thanks.
Is this a double post? If it is do you mind if I remove the other one? If it isn't please let me know so I can adjust the title as needed. http://bytes.com/topic/access/answer...wrong-sql-date - Me!txtdatefrom = Dateserial(Year(Date),month(Date),1)
-
Me!txtDateTo =Dateserial(Year(Date),month(Date),1-1)
-
Hi
Try adding the format function
format(date, "dd/mm/yyyy") or format(date, "short date")
Regards
Emil
@IT Couple
The format function would return a Variant (String) not an actual date if you would like to keep it as a date you would need to convert it like so: - CDate(format(date, "dd/mm/yyyy"))
Just an FYI
The format function would return a Variant (String) not an actual date if you would like to keep it as a date you would need to convert it like so: - CDate(format(date, "dd/mm/yyyy"))
Just an FYI
Good tip thank you!!
Denburt:
The following code: -
Me!txtdatefrom = Dateserial(Year(Date),month(Date),1)
-
Me!txtDateTo =Dateserial(Year(Date),month(Date),1-1)
gave me this:
Start Date: 5/1/09
End Date: 4/30/09
So I changed it to read as -
Me!txtdatefrom = Dateserial(Year(Date),month(Date),1)
-
Me!txtDateTo =Dateserial(Year(Date),month(Date),1+30)
Now I got: Start date: 5/1/09 and End Date 5/31/09
BUT what happens when the month has 28 days or 30 days? Can I include an IIF statement somewhere to make it dynamic?
Thanks.
I should have added a month then subtracted 1-1in the day field to get the last day of any month. Yes I missed a little something there. The following will suit your needs and will take care of the ending date. -
Me!txtdatefrom = Dateserial(Year(Date),month(Date),1)
-
Me!txtDateTo =Dateserial(Year(Date),month(Date)+1,1-1)
@Chinde
Your quite welcome, glad you found it useful.
Denburt: Many thanks. It worked just fine.
How do I close this thread now? Just delete from "my subscription?" Thanks.
i would think that should work I am still getting used to some of the new functionality. So i am hit or miss on a lot of that. Generally I tend to keep myself subscribed (not sure if this is good or not) but if someone else makes a post even a year or so down the road it could be useful information, so I would like a notice but that's me (yeah I am kind of a pack rat).
NeoPa 32,556
Expert Mod 16PB
For this I always use something like : -
Me.txtDateFrom = Format(Date(), "1 mmmm yyyy")
-
Me.txtDateTo = Format(DateAdd("m", 1, Date()) - 1, "d mmmm yyyy")
Sign in to post your reply or Sign up for a free account.
Similar topics
by: K R |
last post by:
Hi,
I have generated this XML from my application. But, when I open this
XML, it is throwing error. Please help me to resolve this.
<?xml version="1.0" encoding="utf-8" ?>
<searchResults>...
|
by: MLH |
last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
'**************************************************************************
' Accepts a date. Determines month & year of the date....
|
by: Soren Jorgensen |
last post by:
Hi,
Following code should give the number of weeks in years 1998-2010 for a
Danish calendar (on a Danish box)
GregorianCalendar cal = new GregorianCalendar();
for(int i = 1998; i < 2010; i++)...
|
by: Terry Olsen |
last post by:
I've got 2 different web pages, both updating the same SQL database. One is
for the Technician and one is for the Manager. The technician's update page
works fine but the Manager's update page...
|
by: Hyphessobrycon |
last post by:
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click
'insert hier
Dim cn As New OleDb.OleDbConnection(constr)
Dim dc As...
|
by: arun_shamli |
last post by:
class CDate
{
public:
CDate() {}
CDate(const CDate& date) {}
};
CDate function1()
{
CDate date();
return date;
|
by: James Conrad StJohn Foreman |
last post by:
After 3 years of using DB2 on Linux, I'm leaving my current employers
to go work for a SQL Server shop instead. In order to find my
replacement, they're trying to put together a set of questions...
|
by: Angus |
last post by:
There are the C runtime library functions of course, but are there any STL
time or date related functions? I couldn't find any.
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - What online resources are available?
-----------------------------------------------------------------------
*...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |