473,748 Members | 2,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting specific Week days

I have tried using the following code to count the specific number of
each weekday but get a compile error "User defined type not defined"
which I think relates to the first line of the function: -

Public Function HowManySpecific Days(StartDate As Date, EndDate As
Date) As DayCounts

and specifically the word "DayCounts"

Can anyone help?

Full code is as follows.

Private Sub CalcDays_Click( )

Call HowManySpecific Days("01/01/2002", "31/12/2002")

Debug.Print "Between these 2 dates there are:"
Debug.Print Count.Mon & " Mondays"
Debug.Print Count.Tue & " Tuesdays"
Debug.Print Count.Wed & " Wednesdays"
Debug.Print Count.Thu & " Thursdays"
Debug.Print Count.Fri & " Fridays"
Debug.Print Count.Mon + Count.Tue + Count.Wed + Count.Thu +
Count.Fri & " Chargeable Days"
Debug.Print Count.TotDays & " Total Days"
End Sub
Public Function HowManySpecific Days(StartDate As Date, EndDate As
Date) As DayCounts

On Error GoTo HowManySpecific Days_Error

Dim dteDateStart As Date
Dim dteDateEnd As Date

Dim intMondays As Integer
Dim intTuesdays As Integer
Dim intWednesdays As Integer
Dim intThursdays As Integer
Dim intFridays As Integer
Dim intTotDays As Integer

Dim intDay As Integer
Dim intMonth As Integer
Dim intMonthCount As Integer

dteDateStart = Format(StartDat e, "dd/mm/yyyy")

dteDateEnd = Format(EndDate, "dd/mm/yyyy")

intMonthCount = 1
intMonth = Month(dteDateSt art)

'Loop through the date range and work out how many days in the
period
Do Until dteDateStart = dteDateEnd + 1

intDay = WeekDay(dteDate Start)

If Not intMonth = Month(dteDateSt art) Then
intMonth = Month(dteDateSt art)
intMonthCount = intMonthCount + 1
End If
Select Case intDay

Case 2 'Mondays
intMondays = intMondays + 1

Case 3 'Tuesdays
intTuesdays = intTuesdays + 1

Case 4 'Wednesdays
intWednesdays = intWednesdays + 1

Case 5 'Thursdays
intThursdays = intThursdays + 1

Case 6 'Fridays
intFridays = intFridays + 1

Case Else

End Select

dteDateStart = dteDateStart + 1
intTotDays = intTotDays + 1
Loop

With Count
.Mon = intMondays
.Tue = intTuesdays
.Wed = intWednesdays
.Thu = intThursdays
.Fri = intFridays
.Months = intMonthCount
.TotDays = intTotDays
End With

HowManySpecific Days = Count

On Error GoTo 0
Exit Function

HowManySpecific Days_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure HowManySpecific Days"

End Function
Nov 12 '05 #1
2 3420

You haven't got a declaration for Count.

This will work
'************** *************** *************** *******
' Version 1
'************** *************** *************** *******
Private Type DayCounts
Mon As Long
Tue As Long
Wed As Long
Thu As Long
Fri As Long
Months As Long
TotDays As Long
End Type

Private Count As DayCounts

Private Sub CalcDays_Click( )
Call HowManySpecific Days("01/01/2002", "31/12/2002")

Debug.Print "Between these 2 dates there are:"
Debug.Print Count.Mon & " Mondays"
Debug.Print Count.Tue & " Tuesdays"
Debug.Print Count.Wed & " Wednesdays"
Debug.Print Count.Thu & " Thursdays"
Debug.Print Count.Fri & " Fridays"
Debug.Print Count.Mon + Count.Tue + Count.Wed + Count.Thu +
Count.Fri & " Chargeable Days"
Debug.Print Count.TotDays & " Total Days"
End Sub
Public Function HowManySpecific Days(StartDate As Date, EndDate As Date) As
DayCounts

On Error GoTo HowManySpecific Days_Error

Dim dteDateStart As Date
Dim dteDateEnd As Date

Dim intMondays As Integer
Dim intTuesdays As Integer
Dim intWednesdays As Integer
Dim intThursdays As Integer
Dim intFridays As Integer
Dim intTotDays As Integer

Dim intDay As Integer
Dim intMonth As Integer
Dim intMonthCount As Integer

dteDateStart = Format(StartDat e, "dd/mm/yyyy")

dteDateEnd = Format(EndDate, "dd/mm/yyyy")

intMonthCount = 1
intMonth = Month(dteDateSt art)

'Loop through the date range and work out how many days in the period
Do Until dteDateStart = dteDateEnd + 1

intDay = Weekday(dteDate Start)

If Not intMonth = Month(dteDateSt art) Then
intMonth = Month(dteDateSt art)
intMonthCount = intMonthCount + 1
End If
Select Case intDay

Case 2 'Mondays
intMondays = intMondays + 1

Case 3 'Tuesdays
intTuesdays = intTuesdays + 1

Case 4 'Wednesdays
intWednesdays = intWednesdays + 1

Case 5 'Thursdays
intThursdays = intThursdays + 1

Case 6 'Fridays
intFridays = intFridays + 1

Case Else

End Select

dteDateStart = dteDateStart + 1
intTotDays = intTotDays + 1
Loop

With Count
.Mon = intMondays
.Tue = intTuesdays
.Wed = intWednesdays
.Thu = intThursdays
.Fri = intFridays
.Months = intMonthCount
.TotDays = intTotDays
End With

HowManySpecific Days = Count

On Error GoTo 0
Exit Function

HowManySpecific Days_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
HowManySpecific Days"

End Function
'************** *************** *************** *******
' /Version 1
'************** *************** *************** *******

But this is better
'************** *************** *************** *******
' Version 2
'************** *************** *************** *******
' In a module on it's own
Public Type DayCounts
Mon As Long
Tue As Long
Wed As Long
Thu As Long
Fri As Long
Months As Long
TotDays As Long
End Type

Public Function HowManySpecific Days(StartDate As Date, EndDate As Date) As
DayCounts

On Error GoTo HowManySpecific Days_Error

Dim dteDateStart As Date
Dim dteDateEnd As Date

Dim intMondays As Integer
Dim intTuesdays As Integer
Dim intWednesdays As Integer
Dim intThursdays As Integer
Dim intFridays As Integer
Dim intTotDays As Integer

Dim intDay As Integer
Dim intMonth As Integer
Dim intMonthCount As Integer

dteDateStart = Format(StartDat e, "dd/mm/yyyy")

dteDateEnd = Format(EndDate, "dd/mm/yyyy")

intMonthCount = 1
intMonth = Month(dteDateSt art)

'Loop through the date range and work out how many days in the period
Do Until dteDateStart = dteDateEnd + 1

intDay = Weekday(dteDate Start)

If Not intMonth = Month(dteDateSt art) Then
intMonth = Month(dteDateSt art)
intMonthCount = intMonthCount + 1
End If
Select Case intDay

Case 2 'Mondays
intMondays = intMondays + 1

Case 3 'Tuesdays
intTuesdays = intTuesdays + 1

Case 4 'Wednesdays
intWednesdays = intWednesdays + 1

Case 5 'Thursdays
intThursdays = intThursdays + 1

Case 6 'Fridays
intFridays = intFridays + 1

Case Else

End Select

dteDateStart = dteDateStart + 1
intTotDays = intTotDays + 1
Loop

With HowManySpecific Days
.Mon = intMondays
.Tue = intTuesdays
.Wed = intWednesdays
.Thu = intThursdays
.Fri = intFridays
.Months = intMonthCount
.TotDays = intTotDays
End With
On Error GoTo 0
Exit Function

HowManySpecific Days_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
HowManySpecific Days"

End Function

' Then called like this from any module
Private Sub CalcDays_Click( )
Dim Count As DayCounts
Count = HowManySpecific Days("01/01/2002", "31/12/2002")

Debug.Print "Between these 2 dates there are:"
Debug.Print Count.Mon & " Mondays"
Debug.Print Count.Tue & " Tuesdays"
Debug.Print Count.Wed & " Wednesdays"
Debug.Print Count.Thu & " Thursdays"
Debug.Print Count.Fri & " Fridays"
Debug.Print Count.Mon + Count.Tue + Count.Wed + Count.Thu +
Count.Fri & " Chargeable Days"
Debug.Print Count.TotDays & " Total Days"
End Sub
'************** *************** *************** *******
' /Version 2
'************** *************** *************** *******

Although whether the code for the HowManySpecific Days function is correct I
wouldn't like to say.

Terry
"David Mitchell" <da************ **@talk21.com> wrote in message
news:c3******** *************** **@posting.goog le.com...
I have tried using the following code to count the specific number of
each weekday but get a compile error "User defined type not defined"
which I think relates to the first line of the function: -

Public Function HowManySpecific Days(StartDate As Date, EndDate As
Date) As DayCounts

and specifically the word "DayCounts"

Can anyone help?

Full code is as follows.

Private Sub CalcDays_Click( )

Call HowManySpecific Days("01/01/2002", "31/12/2002")

Debug.Print "Between these 2 dates there are:"
Debug.Print Count.Mon & " Mondays"
Debug.Print Count.Tue & " Tuesdays"
Debug.Print Count.Wed & " Wednesdays"
Debug.Print Count.Thu & " Thursdays"
Debug.Print Count.Fri & " Fridays"
Debug.Print Count.Mon + Count.Tue + Count.Wed + Count.Thu +
Count.Fri & " Chargeable Days"
Debug.Print Count.TotDays & " Total Days"
End Sub
Public Function HowManySpecific Days(StartDate As Date, EndDate As
Date) As DayCounts

On Error GoTo HowManySpecific Days_Error

Dim dteDateStart As Date
Dim dteDateEnd As Date

Dim intMondays As Integer
Dim intTuesdays As Integer
Dim intWednesdays As Integer
Dim intThursdays As Integer
Dim intFridays As Integer
Dim intTotDays As Integer

Dim intDay As Integer
Dim intMonth As Integer
Dim intMonthCount As Integer

dteDateStart = Format(StartDat e, "dd/mm/yyyy")

dteDateEnd = Format(EndDate, "dd/mm/yyyy")

intMonthCount = 1
intMonth = Month(dteDateSt art)

'Loop through the date range and work out how many days in the
period
Do Until dteDateStart = dteDateEnd + 1

intDay = WeekDay(dteDate Start)

If Not intMonth = Month(dteDateSt art) Then
intMonth = Month(dteDateSt art)
intMonthCount = intMonthCount + 1
End If
Select Case intDay

Case 2 'Mondays
intMondays = intMondays + 1

Case 3 'Tuesdays
intTuesdays = intTuesdays + 1

Case 4 'Wednesdays
intWednesdays = intWednesdays + 1

Case 5 'Thursdays
intThursdays = intThursdays + 1

Case 6 'Fridays
intFridays = intFridays + 1

Case Else

End Select

dteDateStart = dteDateStart + 1
intTotDays = intTotDays + 1
Loop

With Count
.Mon = intMondays
.Tue = intTuesdays
.Wed = intWednesdays
.Thu = intThursdays
.Fri = intFridays
.Months = intMonthCount
.TotDays = intTotDays
End With

HowManySpecific Days = Count

On Error GoTo 0
Exit Function

HowManySpecific Days_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure HowManySpecific Days"

End Function

Nov 12 '05 #2
"Terry Kreft" <te*********@mp s.co.uk> wrote in message news:<bn******* ***@newsreaderm 1.core.theplane t.net>...
You haven't got a declaration for Count.


Terry,

I use this group daily, both to answer questions I have and to
increase my knowledge of all things Access. All to often someone
takes the time to post an answer to a question and there is no follow
up from the original poster.

Thank you, thank you, thank you!

Your solution works perfectly and has transformed my application.

Very best regards

David
Nov 12 '05 #3

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

Similar topics

2
1845
by: Jack | last post by:
To whom may concern: In Asp.Net Calender control, how to display week days, like Wednesday as "Wed", Monday as "Mon", even my windows' region is set to Chinese? Thanks in advance! Jack 2005-10-11
5
1359
by: Jeff | last post by:
Ok, first off, thanks to Bob for all the previous help. I got things running smooth now. My next dilemma isn't from that tour that I inherited, but on my own golf server. On this, only the loser reports the match. So here are my fields. username iloser idate
6
25366
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august 1953 I checked the algorithm it is very correct.
7
25993
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most efficient way for me to do this? -- Thanks, Sam
4
23606
by: MLH | last post by:
MyString = "All men are created equal" Debug.PrintLen(MyString) Now that's easy. But how about just counting the letter "e"? Or, if I were curious to know how many commas were in the string. How might one do this in a query? Suppose a table had single string field with 100 records, each containg a sentence
4
1495
by: Darknight850 | last post by:
Hello all, I am having a rather simple problem that for some reason i can not get to work. i have a date field, and i want to simply count all of the current dates(as in today) in that field. What I have that is not working: count()=Date() as Date Field I know i am missing something, I think I read some were to sum it up, but I tried and that didn't work eather. If some one could help me that would be great.
3
2406
by: Jim | last post by:
Guys I'm rusty. Haven't messed with Access in a while. I'm trying to determine how many workdays (or weekdays) between two dates. I don't think their are any "canned" functions within access - or is there? Can someone help with a simple function count(vbweekdays, startdate,enddate), less stat holidays (LOL!)
3
8281
by: Keo Sophon | last post by:
Fredrik Lundh wrote: Hi, I've tried calendar.month_name, it displays empty string, while calendar.month_name is "January"? Why does calendar.month_name's index not start with index 0 as calendar.day_name? Thanks, Sophon
7
3221
by: Mike | last post by:
I have a routine that's calculating business days but its not counting the weekend days that are between the start date and end date. If my start date is 9/26/08 and my end date is 10/01/08, I should see 4 business days and 2 weekend days. How can I get that result? I'm getting 4 business days but its not counting the weekend days?
0
8994
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
8831
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,...
0
9376
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9329
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
9250
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...
1
6796
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
6076
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
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.