473,948 Members | 9,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong Weeknumber

Hi

I have made this msgbox to display the current Week number, but it
shows the wrong weekno.
Can anyone tell me why ?

msg = "WeekNumber : " & DatePart("WW", Date)
MsgBox msg

It shows weekno = 47 for the date 16 november 2005, but it should be
46.

best regards

Ronald

Nov 16 '05 #1
10 5301
Look at the Help

Maybe you need to use:
msg= "WeekNumber : " & DatePart("WW", Date , , vbFirstFullWeek ) ?

The return value of DatePart depends on what is to be considered as the first day in a given week.
Also Access needs to know what is considered as the first week.

Arno R

<bj**@vestas.co m> schreef in bericht news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Hi

I have made this msgbox to display the current Week number, but it
shows the wrong weekno.
Can anyone tell me why ?

msg = "WeekNumber : " & DatePart("WW", Date)
MsgBox msg

It shows weekno = 47 for the date 16 november 2005, but it should be
46.

best regards

Ronald

Nov 16 '05 #2
bj**@vestas.com wrote:
Hi

I have made this msgbox to display the current Week number, but it
shows the wrong weekno.
Can anyone tell me why ?

msg = "WeekNumber : " & DatePart("WW", Date)
MsgBox msg

It shows weekno = 47 for the date 16 november 2005, but it should be
46.


Check out the 4th parameter to the DatePart function, you should find
what you are looking for for week numbers.
Nov 16 '05 #3
Hi
Thank both of you. The 4th parameter was the clue.

Thank you wery mutch.

Ronald

Nov 16 '05 #4
Hi again.

I also got a query with this SQL phrase:

SELECT Q_AfsluttedeRep Intern.InitSag,
Count(Q_Afslutt edeRepIntern.In itSag) AS CountOfInitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww\/yyyy') AS [DatoAfsl By Week]
FROM Q_AfsluttedeRep Intern
GROUP BY Q_AfsluttedeRep Intern.InitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww\/yyyy');

How shall I do to secure that VB count the weekno. from the first full
week of year ?

best regards
Ronald

Nov 16 '05 #5
Ronald,
Use the same 'trick'. Look in the Help for Format()

Arno R

<bj**@vestas.co m> schreef in bericht news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi again.

I also got a query with this SQL phrase:

SELECT Q_AfsluttedeRep Intern.InitSag,
Count(Q_Afslutt edeRepIntern.In itSag) AS CountOfInitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww\/yyyy') AS [DatoAfsl By Week]
FROM Q_AfsluttedeRep Intern
GROUP BY Q_AfsluttedeRep Intern.InitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww\/yyyy');

How shall I do to secure that VB count the weekno. from the first full
week of year ?

best regards
Ronald

Nov 16 '05 #6
Hi Arno and thank you!

I know I am a novice i VBA versus Access, so I need more help.
I tryed this:

Set oDB = CurrentDb
Set oQuery = oDB.QueryDefs(" Q_3monthBack_Pr od")

VareVar = InputBox("Indta st varenr.:", "Indtast")

mySQL = "SELECT Q_AfsluttedeRep Intern.InitSag,
Count(Q_Afslutt edeRepIntern.In itSag)" & _
"AS CountOfInitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww yyyy',, vbFirstFullWeek ) AS
[DatoAfsl By Week]" & _
"FROM Q_AfsluttedeRep Intern GROUP BY
Q_AfsluttedeRep Intern.InitSag, Format$(T_FejlR ecords.DatoAfsl ,'ww
yyyy',, vbFirstFullWeek )"
oQuery.SQL = mySQL
Set oQuery = Nothing
Set oDB = Nothing

DoCmd.OpenRepor t "R_3MonthBack_P rod", acViewPreview

-and got this message:
Syntax error (missing operator) in query expresion
'Format$(T_Fejl Records.DatoAfs l,'ww yyy',,vbFirstFu llWeek)'.

What is missing or wrong ?

Please help me !

Best regards

Ronald

Nov 16 '05 #7
Ronald,
I think with Format$ used in a query, when you use the 4th param you also need to supply the 3rd (StartDay)
Also you need to use the numeric values here:
So I guess Format$(T_FejlR ecords.DatoAfsl ,'ww yyyy', 1, 3) will work? (I use yyyy, not yyy)
The Constant "1" here means that the week starts at Sunday. (use 2 for Monday)
3 for the last param 'means' the same as vbFirstFullWeek . Again look at the Help for this.

I have a little difficulty here reading your code (my eyes are hazy at the moment ...) but I see some problems here:
-- I don't understand where you use your Inputbox (VareVar)
-- Also you are not using the SQL-string that you are constructing?
Apparently you are changing the SQL of a saved query but you close the query before using it.
==>> oQuery.SQL = mySQL
==>> Set oQuery = Nothing

What exactly are you trying to do, and where are you using this code ??
Is this oQuery.SQL meant to be the recordset for your report??

Btw: As a novice I guess you might be better off using a 'plain' query as the recordset for your report.

Arno R

<bj**@vestas.co m> schreef in bericht news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Hi Arno and thank you!

I know I am a novice i VBA versus Access, so I need more help.
I tryed this:

Set oDB = CurrentDb
Set oQuery = oDB.QueryDefs(" Q_3monthBack_Pr od")

VareVar = InputBox("Indta st varenr.:", "Indtast")

mySQL = "SELECT Q_AfsluttedeRep Intern.InitSag,
Count(Q_Afslutt edeRepIntern.In itSag)" & _
"AS CountOfInitSag,
Format$(T_FejlR ecords.DatoAfsl ,'ww yyyy',, vbFirstFullWeek ) AS
[DatoAfsl By Week]" & _
"FROM Q_AfsluttedeRep Intern GROUP BY
Q_AfsluttedeRep Intern.InitSag, Format$(T_FejlR ecords.DatoAfsl ,'ww
yyyy',, vbFirstFullWeek )"


oQuery.SQL = mySQL
Set oQuery = Nothing
Set oDB = Nothing

DoCmd.OpenRepor t "R_3MonthBack_P rod", acViewPreview

-and got this message:
Syntax error (missing operator) in query expresion
'Format$(T_Fejl Records.DatoAfs l,'ww yyy',,vbFirstFu llWeek)'.

What is missing or wrong ?

Please help me !

Best regards

Ronald

Nov 16 '05 #8
Hi Arno

It works with numbers instead of constantnames. Thank you
The code ?
It was taken from some other place where the SQL statement is
different. I shall use the new SQL in a similar way.
And yes, the code is meant to be the recordset for a report.

best regards
Ronald

Nov 17 '05 #9
Arno R wrote:
I have a little difficulty here reading your code (my eyes are hazy at the moment ...) but I see some problems here:


The police officer pulled the smart aleck over.

Officer: You're eyes look a little hazy. Have you been drinking?

Smart Aleck: Your eyes look a little glazed. Have you been eating
doughnuts?

James A. Fortune

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11361
by: Stig Andersen | last post by:
Hi does anyone know how to make MS SQL server 2000 calculate the right week number around new year ? According to the help file, MSSQL should follow ISO8601, which ensures that i.e. 2003 has only 52 weeks. but these two prove it wrong: Select datepart(ww,'2003/12/31') --(wednesday -> returns 53) Select datepart(ww,'2004/1/1') --(thursday -> returns 1) Well - the weeknumber does not change in the middle of the week. Since
1
1372
by: Vanessa | last post by:
Does anyone know whether when I select a weeknumber of a certain year, eg. 2004, the date from first day to the last day of the week will be known. Regards Vanessa
5
8537
by: DD | last post by:
Hi there, I am working on a sql-query and I need to know the weeknumber of a given date. Could anyone please help me with this. Thanks in advance, Arjen
3
1903
by: dik mus | last post by:
Hi, I connect to a database that only stores the year and weeknumber. But i need the date of the corresponding monday. This could be more difficult as one expect because the weekumbers might change from country to country. (I am looking for a dutch solution.) Thanks, dik
3
5494
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++) { DateTime date = new DateTime(i, 12, 31); int week= cal.GetWeekOfYear(date,
4
3996
by: Morten Snedker | last post by:
In Denmark the 1/1/2009 belongs to week 53 of year 2008. The code below, as I believe should apply to Danish settings, returns 1, which is wrong. Am I having a wrong approach? '--code begin Dim iWeek As Integer
4
4718
by: khicon73 | last post by:
Hello All, I would like to calculate weeknumber and period from first day of the week (sunday) and last day of the week (saturday) and week number falls from 1 to 52 only. If week number >= 53 then week number will equal to 52. And Last Day of First week is the first Saturday of January, as long as it falls at least four days into the month Example: if enter Date WeekNo. Period 12/31/06 1 12/31/06-01/06/07 01/05/07 1 12/31/06-01/06/07...
4
1923
by: Longkhi | last post by:
Hi Everybody. I'm developing a dentist program, which contains a MonthCalender. I would like to select a specific weeknumber, when I select a weeknumber in the MC. I can show the weeknumbers by the code: this.monthCalender1.ShowWeekNumbers = true; Is it possible to make such function? Best regards
1
2627
by: peetersb | last post by:
Hi, I want ot make functions like this: int getFirtDayOfWeek(int weeknumber, int year); int getLastDayOfWeek(int weeknumber, int year); Firts I calculate the count of weeks like this: DateTime lastDay = new DateTime(DateTime.Now.Year, 12, 31);
0
10167
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9989
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11355
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10695
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9898
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8257
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7432
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6340
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.